dropdown.js
dropdown.js copied to clipboard
Not respecting pre-existing selection
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).
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"));
}
Reopen, so this can be merged.
May you send a PR please?
Pushed. Please review. JS is not my strongest language.
+1 , with the fix of FezVrasta/dropdown.js#15 still without work
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
