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

A LayoutMultiSchemaField selector widget gets option indexes where options share or don't pin a selector value

Detect​

  • In your schema and uiSchema: a LayoutMultiSchemaField, as a discriminated layout grid cell renders, whose anyOf/oneOf options include two that read the same ui:optionsSchemaSelector value, such as the options a merge of lists builds from one option, or one that doesn't pin the selector, such as { properties: { kind: { type: 'string' } } } beside options with kind: { const: ... }.
  • In your widgets: a selector ui:widget for such a field that reads value or options.enumOptions[i].value as a selector value, or calls onChange with one.
  • With ui:optionValueFormat: 'realValue': native form data or tests that read the value the select posts.
  • On the rendered page, before: picking an option that shares its selector value with an earlier one showed and switched to the earlier one, and picking the option that pins no value cleared the selection (#5930, #5962).

Change​

The widget of such a field is handed each option's index as its value. A custom selector ui:widget gets the shown option's index as value and in options.enumOptions, and has to call onChange with an index, since any other value clears the selection. value is undefined while the data's selector value names none of the options and the layout grid renders no option's cells, as for a value no option pins or takes, or no value among options sharing one. With ui:optionValueFormat: 'realValue', the select's options post indexes.

The form still writes the picked option's selector value into the data, onFocus and onBlur still get that value, and ui:enumDisabled and ui:optgroups still name selector values.

Have a custom selector widget on such a list report the option it means by its place in options.enumOptions, found by the option's schema with getOptionSelectorValue(), as the form reads it:

-onChange('b');
+onChange(options.enumOptions.findIndex(({ schema }) => getOptionSelectorValue(getPropertySchema(schema, 'kind')) === 'b'));

See oneOf, anyOf, and allOf for the options a merge of lists builds.

Verify​

  • Picking each option shows that option, the one sharing an earlier option's selector value and the one pinning none included.
  • A custom selector widget shows no option selected while value is undefined, and picking one there shows it.
  • The data holds the picked option's selector value, and your onFocus/onBlur handlers, ui:enumDisabled and ui:optgroups still work with selector values.

Also read: