ui:required and omitExtraData follow the anyOf or oneOf option on screen
Detect
- Your uiSchema sets
ui:requiredon a field inside ananyOf/oneOfoption or below a recursive$ref. - Your form passes
omitExtraData(with or withoutliveOmit), and its schema hasanyOf/oneOfoptions. - Tests that submit or live-validate such a form and assert the errors or the data.
Change
The ui:required check and omitting extra data read the option a field shows and the cycles the user expanded. Form passes them through a new optional fieldState argument of getUiRequiredErrorSchema() and omitExtraData().
No code has to change. Update tests; "before" is what 6.11.0 gives:
- With
thing: { anyOf: [{ properties: { aField } }, { properties: { bField } }] },ui:requiredonbFieldand the data{ thing: { aField: 'a' } }, a field showing the second option now blocks the submit for the missingbField. The check used to read the first option, which the data matches best. - With a recursive
nodewhosechildis{ $ref: node },ui:requiredonchild.nameblocks the submit once the user expandschild, and not before. - Omitting keeps the data of the option shown. With
thing: { anyOf: [{ properties: { a } }, { properties: { b } }] }, the data{ thing: { b: 'v' } }and the first option shown, submitting withomitExtraDatadropsb, which the option on screen has no field for. It keptbwhile the option was read from the data. - An edit reads the option the field shows while it is made, so live omitting and live validation agree with the screen. With the root
oneOf: [{ title: 'A', properties: { a: { type: 'string' } } }, { title: 'B', properties: { a: { type: 'string', maxLength: 2 }, b: { type: 'string' } } }],omitExtraDataandliveOmit: 'onChange', selectB, typezintoroot_bandabcintoroot_a. Before: the selector went toA, which the data now matches, andbwas dropped withroot_b. After:Bstays on screen withroot_b, and the data is{ a: 'abc', b: 'z' }. Withui:requiredonbandliveValidate: 'onChange'in place of the omit, the same steps report.b must have required property 'b'underB, where the form showedAand no error.
Verify
- A
ui:requiredfield in the option on screen blocks submit; one in a hidden option or a collapsed cycle doesn't. - With
omitExtraData, submitted data holds the keys of the option on screen. - Omitting still prunes an optional object whose filtered content is all empty, and an
anyOfover empty data still applies every branch, as before.
Also read: