|
@@ -80,6 +80,9 @@ |
|
|
$dynamicInput.find("input").attr("placeholder", options.dynamicOptLabel);
|
|
|
$ul.append($dynamicInput);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
// Cache the dropdown options
|
|
|
var selectOptions = $dropdown.find("li");
|
|
|
|
|
@@ -88,10 +91,11 @@ |
|
|
var $selected;
|
|
|
if ($select.find(":selected").length) {
|
|
|
$selected = $select.find(":selected").last();
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
$selected = $select.find("option, li").first();
|
|
|
+ // $selected = $select.find("option").first();
|
|
|
}
|
|
|
-
|
|
|
methods._select($dropdown, $selected);
|
|
|
} else {
|
|
|
var selectors = [], val = $select.val()
|
|
@@ -124,6 +128,8 @@ |
|
|
// On click, set the clicked one as selected
|
|
|
$ul.on("click", "li:not(.dropdownjs-add)", function(e) {
|
|
|
methods._select($dropdown, $(this));
|
|
|
+ // trigger change event, if declared on the original selector
|
|
|
+ $select.change();
|
|
|
});
|
|
|
$ul.on("keydown", "li:not(.dropdownjs-add)", function(e) {
|
|
|
if (e.which === 27) {
|
|
@@ -135,6 +141,7 @@ |
|
|
return false;
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
$ul.on("focus", "li:not(.dropdownjs-add)", function() {
|
|
|
if ($select.is(":disabled")) {
|
|
|
return;
|
|
@@ -167,6 +174,11 @@ |
|
|
|
|
|
});
|
|
|
|
|
|
+ $select.on("DOMNodeRemoved", function(e) {
|
|
|
+ var deletedValue = e.target.getAttribute('value');
|
|
|
+ $ul.find("li[value='"+deletedValue+"']").remove();
|
|
|
+ });
|
|
|
+
|
|
|
// Update dropdown when using val, need to use .val("value").trigger("change");
|
|
|
$select.on("change", function(e) {
|
|
|
var $this = $(e.target);
|
|
@@ -176,7 +188,8 @@ |
|
|
var $selected;
|
|
|
if ($select.find(":selected").length) {
|
|
|
$selected = $select.find(":selected").last();
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
$selected = $select.find("option, li").first();
|
|
|
}
|
|
|
methods._select($dropdown, $selected);
|
|
@@ -272,7 +285,7 @@ |
|
|
// Toggle option state
|
|
|
$target.toggleClass("selected");
|
|
|
// Toggle selection of the clicked option in native select
|
|
|
- $target.each(function() {
|
|
|
+ $target.each(function(){
|
|
|
var $selected = $select.find("[value=\"" + $(this).attr("value") + "\"]");
|
|
|
$selected.prop("selected", $(this).hasClass("selected"));
|
|
|
});
|
|
@@ -290,7 +303,7 @@ |
|
|
if (!multi) {
|
|
|
// Unselect options except the one that will be selected
|
|
|
if ($target.is("li")) {
|
|
|
- selectOptions.not($target).removeClass("selected");
|
|
|
+ selectOptions.not($target).removeClass("selected");
|
|
|
}
|
|
|
// Select the selected option
|
|
|
$target.addClass("selected");
|
|
@@ -309,10 +322,14 @@ |
|
|
}
|
|
|
}
|
|
|
|
|
|
- // Call the callback
|
|
|
- if (this.options.onSelected) {
|
|
|
- this.options.onSelected($target.attr("value"));
|
|
|
- }
|
|
|
+ // Call the callback
|
|
|
+ if (this.options.onSelected) {
|
|
|
+ this.options.onSelected($target.attr("value"));
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+ _removeOption: function ($ul, $this) {
|
|
|
+ console.warn(arguments);
|
|
|
},
|
|
|
_addOption: function($ul, $this) {
|
|
|
// Create the option
|
|
|
0 comments on commit
0d84a65