Not respecting pre-existing selection #15

Open
NVentimiglia opened this Issue Jun 4, 2015 · 6 comments

Projects

None yet

4 participants

Contributor

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).

Contributor

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"));
}
Contributor

Reopen, so this can be merged.

@NVentimiglia NVentimiglia reopened this Jun 4, 2015
Owner

May you send a PR please?

Contributor

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

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

Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment