slim-select icon indicating copy to clipboard operation
slim-select copied to clipboard

Update click selection to use id of option selected not value

Open gregorwerfel opened this issue 4 years ago • 7 comments

Describe the bug When the user clicks on "Option 2", I expect this option to be displayed as selected as well. Instead, the last matching option with the same value is marked as selected ("Option 5").

<select id="slim-select"> <option value="value1">Option 1</option> <option value="value2">Option 2</option> <option value="value3">Option 3</option> <option value="value2">Option 4</option> <option value="value2">Option 5</option> </select>

Example on CodePen

If using a select in standard HTML (without initializing slim-select), the assignment of the selected option works correctly, even with identical values.

Version: 1.27.0

Screenshots Record_2021_11_15_12_19_21_976_Trim

gregorwerfel avatar Nov 15 '21 11:11 gregorwerfel

New version released today! If this is still an issue let me know.

brianvoe avatar Nov 20 '22 20:11 brianvoe

Problem is still actual in last version 2.8.2. Only behavior changed a bit, but still wrong:

2024-05-28_22-35-44

AlexSus avatar May 28 '24 15:05 AlexSus

its gonna check the first option that has the value cause in slim select we select by value. if you had a better scenario of why you would have the same value twice I might look into making adjustments. but same option values seems incorrect to me but i could be convinced.

brianvoe avatar May 28 '24 16:05 brianvoe

In my opinion, if we are customizing the select tag, it should have the exact same behavior as the standard select. In my example, I have a select tag with IDs of elements divided into optgroups by their parent categories. Some of these IDs can be attached to multiple parents.

For instance, I have an option "1 Bedroom (100 USD)" with the value "52" in the optgroup "Hotel Bangkok" and option "1 Bedroom (200 USD)" with the same value "52" in the optgroup "Hotel Tokyo."

AlexSus avatar May 28 '24 16:05 AlexSus

If you want to submit a pr Ill take a look and see if we can get it merged in.

brianvoe avatar May 28 '24 17:05 brianvoe

Sorry, but I'm not very proficient with JavaScript, so I can't provide good solutuon. For now, I've worked around the issue by changing my option values to make them unique, like "id|parent-id." Then, in my code, I separate the selected value into two parts. This solution looks a bit like a hack and overly complicated.

So I really hope that you or someone else can find an appropriate solution for this problem and implement it in your wonderful script.

AlexSus avatar May 28 '24 17:05 AlexSus

hmm that response was really nice. Ill reopen this issue and update the title a bit

brianvoe avatar May 28 '24 18:05 brianvoe

This will be fixed in the upcoming update

brianvoe avatar Sep 11 '24 20:09 brianvoe