Skip to content

Commit

Permalink
Fixed Bug:1400991 - Modified .off() logic for change events for dropd…
Browse files Browse the repository at this point in the history
…own.

ISSUE: The dropdowns had stopped working at Server-Manager due to previous fix where .off() handlers were introduced to stop triggering of multiple select2 change events
FIX: .off events are applied selectively and it just disables the change function and rest of the events remain unaffected

Change-Id: Ib2468ef9df52ac9fbc68c251be1bd92462b79344
  • Loading branch information
Sagar Gala committed Dec 10, 2014
1 parent 94f609e commit 1aae8cc
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions webroot/js/contrail-elements.js
Expand Up @@ -971,6 +971,12 @@ function constructSelect2(self, defaultOption, args) {
option.dataTextField = {dsVar: option.dataTextField, apiVar: 'text'};
option.dataValueField = {dsVar: option.dataValueField, apiVar: 'id'};

var changeFunction = function(e) {
if (contrail.checkIfFunction(option.change)) {
option.change(e);
}
};

if(!$.isEmptyObject(option) && typeof option.dataSource !== 'undefined') {
if(option.dataSource.type == "remote"){
$.ajax({
Expand All @@ -993,13 +999,17 @@ function constructSelect2(self, defaultOption, args) {
}
if(typeof option.data != "undefined") {
option.data = formatData(option.data,option);

if (contrail.checkIfExist(self.data('contrailDropdown'))) {
self.data('contrailDropdown').destroy();
}

if (contrail.checkIfExist(self.data('contrailMultiselect'))) {
self.data('contrailMultiselect').destroy();
}

self.select2(option)
.off("change")
.on("change", function(e) {
if (typeof option.change !== 'undefined' && typeof option.change === 'function') {
option.change(e);
}
});
.on("change", changeFunction);
if (option.data.length !=0) {
self.select2('val', option.data[0].text);
}
Expand Down Expand Up @@ -1062,12 +1072,8 @@ function constructSelect2(self, defaultOption, args) {
}

self.select2(option)
.off("change")
.on("change", function(e) {
if (typeof option.change !== 'undefined' && typeof option.change === 'function') {
option.change(e);
}
});
.off("change", changeFunction)
.on("change", changeFunction);

if(option.data.length > 0){
if(option.data[0].children != undefined && option.data[0].children.length > 0) {
Expand Down Expand Up @@ -1118,7 +1124,8 @@ function constructSelect2(self, defaultOption, args) {
return true;
},
destroy: function(){
self.select2('destroy');
self.off("change", changeFunction)
.select2('destroy');
},
hide: function() {
self.select2("container").hide();
Expand Down

0 comments on commit 1aae8cc

Please sign in to comment.