-
Notifications
You must be signed in to change notification settings - Fork 171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow for an empty option in select fields via schema property #4036
Comments
So, in this scenario, what do you want the submitted JSON to look like? An empty array, or the property should not exist at all? |
The property should not exist at all. |
We are trying to reproduce the behavior of react-jsonschema-form as much as possible, and it looks like there an enum field that is optional should always have an empty element in the select, which translates to no property in the JSON. We should make json_form_widget work the same way. |
Okay, then we could just use |
I think so! Does it produce the expected result? |
Yes, no value is saved in the JSON if the empty option is chosen. Updated the PR. |
…tests, code style
User Story
Currently you can not make use of the #empty_value property of the Drupal Select form element if using the basic select widget with the json_form_widget for a schema field.
You can use the select_other type for the list widget, but then you get the empty option and the other option.
There maybe cases where you only want the empty option but not allow the other option, i. e. an optional list field.
I propose to use a schema property on the dataset field to indicate this. Why not just name this "empty_value" and if this is set to true the #empty_value property will be used on the select form element.
One could maybe just inject an empty value in the "enum" property of the schema field, but this seems kind of "dirty".
Acceptance Criteria
The text was updated successfully, but these errors were encountered: