Commit 46c62ee3 authored by Piotr Zygmuntowicz's avatar Piotr Zygmuntowicz

Option added for preventing generated inputs (radio or checkboxes) from firing...

Option added for preventing generated inputs (radio or checkboxes) from firing change event (in my case that was unnecessary, change event on select was enough)
parent 4820c2c6
...@@ -120,7 +120,8 @@ ...@@ -120,7 +120,8 @@
enableCaseInsensitiveFiltering : false, enableCaseInsensitiveFiltering : false,
filterPlaceholder : 'Search', filterPlaceholder : 'Search',
// possible options: 'text', 'value', 'both' // possible options: 'text', 'value', 'both'
filterBehavior : 'text' filterBehavior : 'text',
preventInputChangeEvent: false
}, },
constructor : Multiselect, constructor : Multiselect,
...@@ -270,6 +271,10 @@ ...@@ -270,6 +271,10 @@
this.options.onChange($option, checked); this.options.onChange($option, checked);
this.$select.change(); this.$select.change();
if(this.options.preventInputChangeEvent) {
return false;
}
}, this)); }, this));
$('.multiselect-container li a', this.$container).on('touchstart click', function(event) { $('.multiselect-container li a', this.$container).on('touchstart click', function(event) {
...@@ -338,52 +343,52 @@ ...@@ -338,52 +343,52 @@
$('.multiselect-search', this.$container).val(this.query).on('click', function(event) { $('.multiselect-search', this.$container).val(this.query).on('click', function(event) {
event.stopPropagation(); event.stopPropagation();
}).on('keydown', $.proxy(function(event) { }).on('keydown', $.proxy(function(event) {
// This is useful to catch "keydown" events after the browser has // This is useful to catch "keydown" events after the browser has
// updated the control. // updated the control.
clearTimeout(this.searchTimeout); clearTimeout(this.searchTimeout);
this.searchTimeout = this.asyncFunction($.proxy(function() { this.searchTimeout = this.asyncFunction($.proxy(function() {
if (this.query != event.target.value) { if (this.query != event.target.value) {
this.query = event.target.value; this.query = event.target.value;
$.each($('.multiselect-container li', this.$container), $.proxy(function(index, element) { $.each($('.multiselect-container li', this.$container), $.proxy(function(index, element) {
var value = $('input', element).val();
if (value != this.options.selectAllValue) {
var text = $('label', element).text();
var value = $('input', element).val(); var value = $('input', element).val();
if (value && text && value != this.options.selectAllValue) { if (value != this.options.selectAllValue) {
// by default lets assume that element is not var text = $('label', element).text();
// interesting for this search var value = $('input', element).val();
var showElement = false; if (value && text && value != this.options.selectAllValue) {
// by default lets assume that element is not
var filterCandidate = ''; // interesting for this search
if ((this.options.filterBehavior == 'text' || this.options.filterBehavior == 'both')) { var showElement = false;
filterCandidate = text;
} var filterCandidate = '';
if ((this.options.filterBehavior == 'value' || this.options.filterBehavior == 'both')) { if ((this.options.filterBehavior == 'text' || this.options.filterBehavior == 'both')) {
filterCandidate = value; filterCandidate = text;
} }
if ((this.options.filterBehavior == 'value' || this.options.filterBehavior == 'both')) {
if (this.options.enableCaseInsensitiveFiltering && filterCandidate.toLowerCase().indexOf(this.query.toLowerCase()) > -1) { filterCandidate = value;
showElement = true; }
}
else if (filterCandidate.indexOf(this.query) > -1) { if (this.options.enableCaseInsensitiveFiltering && filterCandidate.toLowerCase().indexOf(this.query.toLowerCase()) > -1) {
showElement = true; showElement = true;
} }
else if (filterCandidate.indexOf(this.query) > -1) {
if (showElement) { showElement = true;
$(element).show(); }
}
else { if (showElement) {
$(element).hide(); $(element).show();
}
else {
$(element).hide();
}
} }
} }
} }, this));
}, this)); }
} }, this), 300, this);
}, this), 300, this); }, this));
}, this));
}, },
// Destroy - unbind - the plugin. // Destroy - unbind - the plugin.
...@@ -471,7 +476,7 @@ ...@@ -471,7 +476,7 @@
$('.multiselect-container', this.$container).html(''); $('.multiselect-container', this.$container).html('');
this.buildDropdown(this.$select, this.options); this.buildDropdown(this.$select, this.options);
this.updateButtonText(); this.updateButtonText();
// Enable filtering. // Enable filtering.
if (this.options.enableFiltering || this.options.enableCaseInsensitiveFiltering) { if (this.options.enableFiltering || this.options.enableCaseInsensitiveFiltering) {
this.buildFilter(); this.buildFilter();
...@@ -527,4 +532,4 @@ ...@@ -527,4 +532,4 @@
$("select[data-role=multiselect]").multiselect(); $("select[data-role=multiselect]").multiselect();
}); });
}(window.jQuery); }(window.jQuery);
\ No newline at end of file
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