question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UiSelect default value not marked as "selected"

See original GitHub issue

When 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:closed
  • Created 7 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
JosephusPayecommented, Aug 11, 2016

The options and defaults 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.

1reaction
JosephusPayecommented, Jun 1, 2016

The problem is that at the moment the value passed to the default prop must be in the options 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 with text and value properties.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set default value in material-UI select box in react?
I want to show "select the value" option by default selected but after that user is not able to select this option. <FormControl...
Read more >
Selected item is not being marked as selected in the choices
To reproduce, open the ui-select and choose "Adrian" then open the ui-select again and "Adam" will be marked as selected. This plunker binds...
Read more >
How to set default value in a Touch UI select element?
Solved: I am trying to set the defaultValue in a Touch UI select dropdown. Setting "defaultValue" in dialog.xml works in Classic - 189815....
Read more >
How to set the default value for an HTML <select> element
The default value of the select element can be set by using the 'selected' attribute on the required option. This is a boolean...
Read more >
Select - Ant Design
It's caused by option with different label and value . You can use optionFilterProp="label" to change filter logic instead. When I click elements...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found