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

getClosestMatchingOption scores an option's if and dependencies for the data

Detect​

  • In your schema: an anyOf or oneOf option that holds an if or dependencies, itself or in an allOf entry (#5990).
  • In your code or tests: a call to getClosestMatchingOption() or getDefaultFormState() with such options, or a test that asserts the option a form opens on or the defaults it fills.
  • On the rendered page, before: the form opened on another option than the one it shows after reset() for the same data.

Change​

An option passed as written was scored without the branch that applies to the data, while the option selector scored it with that branch. It is now scored with the branch, so a form opens on the option it shows after reset(), and getDefaultFormState() fills that option's defaults.

With these options and the data { "kind": "a", "n": 1 }, the form opened on B, whose own properties name both keys. Both options now describe both keys, so it opens on the first, A:

[
{
"title": "A",
"properties": { "kind": { "type": "string" } },
"if": { "properties": { "kind": { "const": "a" } }, "required": ["kind"] },
"then": { "properties": { "n": { "type": "number" } } }
},
{ "title": "B", "properties": { "kind": { "type": "string" }, "n": { "type": "number" } } }
]

Update tests that expect the old pick or its defaults. To open on another option, list it first, or tell the options apart by a const property or a discriminator.

Verify​

  • The form's first render and reset() show the same option for the same data, with that option's defaults.

Also read: