UiSelect default value not marked as "selected"
See original GitHub issueWhen I use the Select component and want to edit a resource on my app, I cannot make the values pre-selected.
With multiple off, the value is not selected (which is not a problem), but with multiple on, the checkboxes are not checked, and when I “check” it the values get duplicated.
I’m absolutely no expert, but analyzing the code, I think the problem is on UiSelect, setDefaultValue method. For some reason, this.options[i] === defaults[j] is never true, even if it is true.
Can it be changed to this.options[i].value === defaults[j].value or something like this?
On a side note, I think requiring an array with “text” doesn’t make sense… the important thing in a select option is the value… Can It be able to recognize different patterns, being the “value” the only required thing?
1st (value = text): [value1, value2, value3]
2nd: [{'value': value1, 'text': 'text to value1'}, {'value': value2, 'text': 'text to value2'}]
3rd: [{value1: 'text to value1'}, {value2: 'text to value2'}]
Also being able to accept a pattern as the options (like the 2nd one for example), and a different pattern as the value/default (because only the value matters, the text is only “aesthetic”).
It would be great if you could make it happen!
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (4 by maintainers)
The
options
anddefaults
prop for UiSelect has been overhauled in v0.8.9.It now supports all your examples above, as you can customize the keys using the new
keys
prop.See the UiSelect docs.
The problem is that at the moment the value passed to the
default
prop must be in theoptions
array (as in they must be references to the same object) for the equality to match. This is fixed in #37, which will be merged for v0.8.9.As for the
options
array format, I plan to support your 1st example in addition to the 2nd one, which is the current format. This will bring the API more in line with UiAutocomplete, which supports a simple array of strings as well as objects withtext
andvalue
properties.