reset() shows the anyOf or oneOf option a mount on the seed shows
Detect
.reset()called with no argument on aFormref, on a form whose schema hasanyOforoneOf.- Tests that select an option, call
reset()and then assert which option or which inputs show. - On the rendered page: a selector that stayed on the option the user picked through a reset now goes back to the option the form opened on.
Change
reset() with no argument puts each anyOf/oneOf field back on the option a form mounting on the seed shows. v6 did the same where the seed's data, with the defaults filled in, fits one option better than the others. Where the data can't tell the options apart, v6 left the field on the option the user had picked:
const schema = {
oneOf: [
{ title: 'A', type: 'object', properties: { a: { type: 'string' } } },
{ title: 'B', type: 'object', properties: { b: { type: 'string' } } },
],
};
// The form mounts on A. Select B, then call reset()
v6 stayed on B. v7 goes back to A, as both do where a and b each have a default. The same goes for a form passed formData that stores every edit: its data stays, and each field shows the option that data matches.
An option the user picked stays picked through reset(saved) where the saved data still fits it, and a later reset() returns to it. See Making the saved data the baseline.
No code has to change. If a test expects the picked option after a reset(), expect the option a form mounting on the seed shows.
Verify
- After the user picks an option and
reset()runs, the form shows the option and the data a form mounting on the seed shows. - After
reset(saved), a laterreset()shows the options the form showed whenreset(saved)ran.
If you can't preserve it
No setting keeps the pick through reset(). For a field to come back on a given option, the seed has to hold data that option alone matches, such as a property each option gives its own const, or a declared discriminator.
Also read: