A LayoutMultiSchemaField selector widget gets option indexes where options share or don't pin a selector value
Detect
- In your schema and
uiSchema: aLayoutMultiSchemaField, as a discriminated layout grid cell renders, whoseanyOf/oneOfoptions include two that read the sameui:optionsSchemaSelectorvalue, 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 withkind: { const: ... }. - In your
widgets: a selectorui:widgetfor such a field that readsvalueoroptions.enumOptions[i].valueas a selector value, or callsonChangewith 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
valueisundefined, and picking one there shows it. - The data holds the picked option's selector value, and your
onFocus/onBlurhandlers,ui:enumDisabledandui:optgroupsstill work with selector values.
Also read: