Skip to main content
Version: Current (v7.0.0-beta.3)

A cleared field takes the default of the field that replaces it

Detect​

  • In your schema, a field whose type, const, enum (or the constants of its anyOf/oneOf), maxItems or default changes through an if/then, an option switch or a new schema prop.
  • In your schema, an anyOf/oneOf of constants with a default, used under mergeDefaultsIntoFormData: 'useDefaultIfFormDataUndefined'.
  • On the rendered page, a field the user cleared that now fills in, or stays empty, after one of those changes.

Change​

Two cases of a field the user cleared behave differently now, and neither can be turned off:

  • When a field's type, const, enum (or the constants of its anyOf/oneOf), maxItems or default changes, a clear of it gives way to the new field's default under every mergeDefaultsIntoFormData. The field used to stay empty. A disabled or readonly form keeps and gives way to its clears the same way, and so does any other key holding undefined. Every value stays as it is, including a null item the user didn't clear.
  • Under mergeDefaultsIntoFormData: 'useDefaultIfFormDataUndefined', an anyOf/oneOf field of constants with a default stays cleared, as any other field does. Its default used to come back.

If your form relied on the old result, restore it from transformChange, which gets the data an edit settled on. Write undefined back for a field that has to stay empty, or the default for one that has to take it again:

const transformChange = (next) => (next?.kind === 'other' ? { ...next, detail: undefined } : next);

A new schema prop runs no transformChange, so a field that has to stay empty through one needs its data set after the change, with setFieldValue().

Verify​

If you can't preserve it​

Neither case has an option to turn it off. The only way back to the old result is to set the data yourself, from transformChange for edits or with setFieldValue() after a new schema prop.

Also read: