This commit is contained in:
guillim
2024-11-20 18:03:35 +01:00
parent 5ab4f71bc6
commit c89a07a20e
2 changed files with 26 additions and 25 deletions

View File

@@ -45,12 +45,12 @@ export const computeDraftValueFromFieldValue = <FieldValue>({
if (isFieldAddress(fieldDefinition)) { if (isFieldAddress(fieldDefinition)) {
if ( if (
isFieldValueEmpty({ fieldValue, fieldDefinition }) isFieldValueEmpty({ fieldValue, fieldDefinition }) &&
&& fieldDefinition.metadata.settings?.defaultCountry !!fieldDefinition.metadata.settings?.defaultCountry
) { ) {
return { return {
...fieldValue, ...fieldValue,
addressCountry: fieldDefinition.metadata.settings.defaultCountry addressCountry: fieldDefinition.metadata.settings.defaultCountry,
} as unknown as FieldInputDraftValue<FieldValue>; } as unknown as FieldInputDraftValue<FieldValue>;
} }

View File

@@ -40,15 +40,16 @@ export const SettingsDataModelFieldAddressForm = ({
fieldMetadataItem, fieldMetadataItem,
}: SettingsDataModelFieldAddressFormProps) => { }: SettingsDataModelFieldAddressFormProps) => {
const { control } = useFormContext<SettingsDataModelFieldTextFormValues>(); const { control } = useFormContext<SettingsDataModelFieldTextFormValues>();
const countries = useCountries().map(country => ({ const countries = useCountries().map((country) => ({
label: country.countryName, label: country.countryName,
value: country.countryName value: country.countryName,
})) }));
return ( return (
<Controller <Controller
name="settings" name="settings"
defaultValue={{ defaultValue={{
defaultCountry: fieldMetadataItem?.settings?.defaultCountry || 'United States', defaultCountry:
fieldMetadataItem?.settings?.defaultCountry || 'United States',
}} }}
control={control} control={control}
render={({ field: { onChange, value } }) => { render={({ field: { onChange, value } }) => {