Skip to content

Commit

Permalink
[CA-4542] Value the phone number to null when not specified (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
sachaMemmir5 authored Jan 28, 2025
1 parent 310ffee commit a072d3e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import dts from 'rollup-plugin-dts'
import css from 'rollup-plugin-import-css'
import esbuild from 'rollup-plugin-esbuild'

import pkg from './package.json' assert { type: 'json' }
import pkg from './package.json' with { type: 'json' }
const dependencies = Object.keys(pkg.dependencies)

const banner = [
Expand Down
9 changes: 6 additions & 3 deletions src/components/form/fields/phoneNumberField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { FormGroup } from '../formControlsComponent';
import { Validator } from '../../../core/validation';
import { Config, Optional } from '../../../types';
import { Input } from '../formControlsComponent';
import {isRichFormValue} from "../../../helpers/utils.ts";

function isValidCountryCode(code?: string): code is Country {
return typeof code === 'string' && isSupportedCountry(code)
Expand Down Expand Up @@ -86,6 +87,8 @@ const PhoneNumberField = (props: PhoneNumberFieldProps) => {
} = props;

const [labels, setLabels] = useState<Labels>()
const currentValue = isRichFormValue(value, 'raw') ? value.raw : value
const error = typeof validation === 'object' && 'error' in validation ? validation.error : undefined

useEffect(() => {
async function fetchLabels() {
Expand All @@ -100,14 +103,14 @@ const PhoneNumberField = (props: PhoneNumberFieldProps) => {
*/
let ignore = false;
fetchLabels();
onChange({
value: currentValue == "" ? undefined: currentValue
})
return () => {
ignore = true;
}
}, [locale])

const currentValue = value !== null && typeof value === 'object' && 'raw' in value ? value.raw : value
const error = typeof validation === 'object' && 'error' in validation ? validation.error : undefined

const handlePhoneChange = (value: Value) => {
onChange({
value,
Expand Down

0 comments on commit a072d3e

Please sign in to comment.