Create a select field (drop-down) with a valid null-value when selection is empty/cleared #4459
-
What do I have to do to get normal looking selection field with only value1 and value2 as choices for the user and the ability to clear it, which will produce I know how to create a select field with a "set of choices", like:
However, if I clear the field, then "select_static" drops out of the formData and it will be empty: I need a behaviour, where
I got that adding So I also changed JSONschema like this, by making
This will successfully validate (so Requirement 2 fulfilled), but it will also add "null" to the selection list, which is strange for the user: He now has an empty list entry and also the null entry, which both will produce (I also tried different other things, but many resulted in a drop-down plus a text field, which really confused me) Bonus question: i would like to have "null" as the default value (just came to my mind, did not yet test if this is difficult) What do I have to do to get normal looking selection field with only value1 and value2 as choices for the user and the ability to clear it, which will produce Edit: I used the playground (https://rjsf-team.github.io/react-jsonschema-form/) to fiddle around. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I figured out that I have to adjust my JSONSchema to the following:
or
With any of these JSONschemas, the accepted JSON objects will be: However, with the second JSONschema, rjsf will render the form strangely, it will consist of an input field and a drop-down/select. What do I have to customize and how do I have to adjust my UIschema, to write my own component, which shall display my own selection drop-down and where I will implement that clearing results in (Edit: formatting) |
Beta Was this translation helpful? Give feedback.
After some further digging in the other rjsf forums for Issues I found this post #4422
and finally adjusted the
properties
to this:This will produce a selection drop-down with three entries.
If I do nothing further, it will show " - " to the user, which will produce
null
.To make it a…