setFieldValue fills in the defaults of the value it writes
Detect
mergeDefaultsIntoFormData: 'useDefaultIfFormDataUndefined'in yourdefaultFormStateBehavior.- Calls to
setFieldValue(path, undefined)in your code at a field whose schema has adefault, where you expect the field to stay empty. - An
undefinedin your seed that you expect to stay empty when a default arrives later.
Change
Under mergeDefaultsIntoFormData: 'useDefaultIfFormDataUndefined', setFieldValue(path, undefined) at a field with a default used to leave the field empty, while setFieldValue('', data) filled the same field's default back in. Both now fill it in, as the form does for any data it holds. Only the fields the user cleared stay empty. An undefined that setFieldValue() or the seed put there also takes a default that arrives later, such as one a new schema prop gives an object holding the field.
A form that has to leave a field empty from code can keep mergeDefaultsIntoFormData at its default, 'useFormDataIfPresent', under which a field set to undefined stays undefined:
-<Form defaultFormStateBehavior={{ mergeDefaultsIntoFormData: 'useDefaultIfFormDataUndefined' }} />
+<Form defaultFormStateBehavior={{ mergeDefaultsIntoFormData: 'useFormDataIfPresent' }} />
Verify
- A field you set to
undefinedfrom code shows itsdefault, or stays empty under'useFormDataIfPresent'. - Fields the user cleared still stay empty.
Also read: