dropdown.js icon indicating copy to clipboard operation
dropdown.js copied to clipboard

Not respecting pre-existing selection

Open NVentimiglia opened this issue 10 years ago • 6 comments

Does not respect initial values. For instance I have a form which has a default selection (from a previous submission). This value is correct and present without the plugin. When I apply the plugin the selection is nulled and the .val() is incorrect.

It would be nice if the plugin respected preexisting values.

Here is my code.

<select class="form-control select width-150" id="RoleState" name="RoleState">
<option value="">Role State</option>
<option value="0">Pending</option>
<option selected="selected" value="1">Approved</option>
<option value="2">Rejected</option>
</select>

After I apply .dropdown() the selection becomes the first (RoleState).

NVentimiglia avatar Jun 04 '15 16:06 NVentimiglia

Fix

// If is a single select, selected the first one or the last with selected attribute
if (!multi) {
    var $selected;
    if ($select.find(":selected").length) {
        $selected = $select.find(":selected").last();
    }
    else {
        $selected = $select.find("li").first();
    }
    methods._select($dropdown, $selected);
} else {
    methods._select($dropdown, $select.find(":selected"));
}

NVentimiglia avatar Jun 04 '15 16:06 NVentimiglia

Reopen, so this can be merged.

NVentimiglia avatar Jun 04 '15 16:06 NVentimiglia

May you send a PR please?

FezVrasta avatar Jun 04 '15 20:06 FezVrasta

Pushed. Please review. JS is not my strongest language.

NVentimiglia avatar Jun 04 '15 20:06 NVentimiglia

+1 , with the fix of FezVrasta/dropdown.js#15 still without work

sdkcarlos avatar Jun 18 '15 00:06 sdkcarlos

line 292 https://github.com/FezVrasta/dropdown.js/blob/master/jquery.dropdown.js#L292

var $option = $("<li></li>");
console.log($option);

is creating 1st li element with class "selected" can't find why. anyone?

1st is selected while 2nd should be selected

here's

selected

liesislukas avatar Jun 20 '15 12:06 liesislukas