Form no longer calls onChange on mount for defaults or null fields
Detect
- An
onChangein your code that you expect to run when the form mounts, to receive the schema's defaults or atype: 'null'field'snull. - A copy of the data kept only from
onChange, which you read before the user edits anything. - A
type: 'null'property in your schema that aLayoutGridFieldlayout leaves out, or that sits under aui:fieldthat doesn't render it.
Change
The form fills its seed in with the schema's defaults on mount, and again when the schema, a ui:emptyValue, defaultFormStateBehavior or additionalPropertiesWhenAbsent changes. It no longer calls onChange for that. v6 called onChange for those defaults from its constructor, and the field of a type: 'null' schema called onChange(null) as it mounted.
If you keep a copy of the data from onChange, that copy has no defaults until the first edit, which holds for the formData you pass too: the form shows it with the defaults filled in, and reports them with the first edit. Read getFormData() when you need the value with its defaults, or take it from the onSubmit event:
-const onChange = ({ formData }) => setData(formData);
-const save = () => api.save(data);
+const save = () => api.save(formRef.current.getFormData());
Verify
- Data you read before the first edit includes the schema's defaults.
- A missing
type: 'null'value is filled in asnulllike any other default, whateveremptyObjectFieldssays, so the submitted data is unchanged wherever that field rendered. - A
type: 'null'property left out of aLayoutGridFieldlayout, or under aui:fieldthat doesn't render it, is now submitted asnullwhere it was absent. - An object holding a
type: 'null'field that you set toundefined, withsetFieldValue()ortransformChange, now staysundefined. The field used to put itsnullback and re-create the object with its defaults.
Also read: