Commit 33311d45 authored by Chris Hynes's avatar Chris Hynes

Made single selection checking work properly so .val() returns correctly

Removed browser sniffing for IE and use :selected pseudoselector everywhere
parent cd210f94
...@@ -122,9 +122,9 @@ ...@@ -122,9 +122,9 @@
constructor: Multiselect, constructor: Multiselect,
// Add the [] Select all option // Add the [] Select all option
createSelectAllOption: function () { createSelectAllOption: function () {
$(this.$select).html('<option value="select-all-option"> Select all</option>' + this.$select.html()); $(this.$select).html('<option value="select-all-option"> Select all</option>' + this.$select.html());
}, },
// Will build an dropdown element for the given option. // Will build an dropdown element for the given option.
createOptionValue: function(element) { createOptionValue: function(element) {
...@@ -159,10 +159,10 @@ ...@@ -159,10 +159,10 @@
// Build the dropdown and bind event handling. // Build the dropdown and bind event handling.
buildDropdown: function () { buildDropdown: function () {
//If options.includeSelectAllOption === true, add the include all checkbox //If options.includeSelectAllOption === true, add the include all checkbox
if (this.options.includeSelectAllOption && this.options.multiple) { if (this.options.includeSelectAllOption && this.options.multiple) {
this.createSelectAllOption(); this.createSelectAllOption();
} }
this.$select.children().each($.proxy(function (index, element) { this.$select.children().each($.proxy(function (index, element) {
// Support optgroups and options without a group simultaneously. // Support optgroups and options without a group simultaneously.
var tag = $(element).prop('tagName').toLowerCase(); var tag = $(element).prop('tagName').toLowerCase();
...@@ -207,12 +207,13 @@ ...@@ -207,12 +207,13 @@
var $checkboxesNotThis = $('input', this.$container).not($(event.target)); var $checkboxesNotThis = $('input', this.$container).not($(event.target));
if (isSelectAllOption) { if (isSelectAllOption) {
$checkboxesNotThis.filter(function () { return $(this).is(':checked') != checked; }).trigger('click'); $checkboxesNotThis.filter(function () { return $(this).is(':checked') != checked; }).trigger('click');
} }
if (checked) { if (checked) {
option.attr('selected', 'selected').prop('selected', true); option.prop('selected', true);
if (!this.options.multiple) { if (!this.options.multiple)
{
if (this.options.selectedClass) { if (this.options.selectedClass) {
$($checkboxesNotThis).parents('li').removeClass(this.options.selectedClass); $($checkboxesNotThis).parents('li').removeClass(this.options.selectedClass);
} }
...@@ -220,7 +221,7 @@ ...@@ -220,7 +221,7 @@
$($checkboxesNotThis).prop('checked', false); $($checkboxesNotThis).prop('checked', false);
$optionsNotThis.removeAttr('selected').prop('selected', false); $optionsNotThis.removeAttr('selected').prop('selected', false);
// It's a single selection, so close. // It's a single selection, so close.
$(this.$container).find(".multiselect.dropdown-toggle").click(); $(this.$container).find(".multiselect.dropdown-toggle").click();
} }
...@@ -228,9 +229,10 @@ ...@@ -228,9 +229,10 @@
if (this.options.selectedClass == "active") { if (this.options.selectedClass == "active") {
$optionsNotThis.parents("a").css("outline", ""); $optionsNotThis.parents("a").css("outline", "");
} }
} }
else { else {
option.removeAttr('selected'); option.removeAttr('selected').prop('selected', false);
} }
var options = this.getSelected(); var options = this.getSelected();
...@@ -377,14 +379,14 @@ ...@@ -377,14 +379,14 @@
// For IE 9 support. // For IE 9 support.
getSelected: function() { getSelected: function() {
if (navigator.appName == 'Microsoft Internet Explorer') { //if (navigator.appName == 'Microsoft Internet Explorer') {
var regex = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); // var regex = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (regex.exec(navigator.userAgent) != null) { // if (regex.exec(navigator.userAgent) != null) {
return $('option:selected[value!="select-all-option"]', this.$select); // return $('option:selected[value!="select-all-option"]', this.$select);
} // }
} //}
return $('option[selected][value!="select-all-option"]', this.$select); return $('option:selected[value!="select-all-option"]', this.$select);
} }
}; };
...@@ -405,8 +407,8 @@ ...@@ -405,8 +407,8 @@
}); });
} }
$(function() $(function()
{ {
$("select[data-role=multiselect]").multiselect(); $("select[data-role=multiselect]").multiselect();
}); });
}(window.jQuery); }(window.jQuery);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment