ravi sharma

ravi sharma

  • NA
  • 87
  • 16.6k

Backbone model triggering dropdown change event twice

Sep 26 2016 3:45 AM
Hi All,
 
When I am changing dropdown, dropdown change event is triggering twice. Following is the code. Please suggest.
 
 
nspace("siriusd.views");
(function ($, _, window, document) {
siriusd.views.DropdownFilterView = siriusd.views.FilterView.extend({
events: {
"change": "changeFilter"
},
initialize: function (options) {
siriusd.views.DropdownFilterView.__super__.initialize.apply(this, arguments);
this.el = options.el;
this.filterKeys = options.filterKeys;
this.setValue();
this.collection.setFilter(this.filter);
},
setValue: function () {
var value = this.getSelectedValue();
// don't filter on options with value set to zero
if (parseInt(value, 10) === 0) {
this.removeFilter(this.filterKeys.selected);
} else {
this.addFilter(this.filterKeys.selected, value);
}
},
resetValue: function () {
if (this.$el.attr('id') != 'domain' && this.$el.attr('id') != 'subject' && this.$el.attr('id') != 'focusarea' && this.$el.attr('id') != 'topic') {
this.$el.find("option:first").attr('selected', 'selected');
this.$el.trigger('change');
this.$el.heapbox('update');
}
// avoid to getitems call for subject , focusarea, topic new ...
else if (this.$el.attr('id') == 'domain') {
$("#domain").val($("#domain option:first").val());
$("#domain").trigger('change');
}
},
changeFilter: function () {
this.setValue();
this.collection.setFilter(this.filter);
this.filtrate();
},
getSelectedValue: function () {
if (this.$el.attr('id') == 'subject') {
if (this.$el.find(":selected").val() != '') {
return ($("#domain").find(":selected").val() + '::' + this.$el.find(":selected").val());
}
else {
return ($("#domain").find(":selected").val());
}
}
else if (this.$el.attr('id') == 'focusarea') {
if (this.$el.find(":selected").val() != '') {
return ($("#domain").find(":selected").val() + '::' + $("#subject").find(":selected").val() + '::' + this.$el.find(":selected").val());
}
else {
return ($("#domain").find(":selected").val() + '::' + $("#subject").find(":selected").val());
}
}
else if (this.$el.attr('id') == 'topic') {
if (this.$el.find(":selected").val() != '') {
return ($("#domain").find(":selected").val() + '::' + $("#subject").find(":selected").val() + '::' + $("#focusarea").find(":selected").val() + '::' + this.$el.find(":selected").val());
}
else {
return ($("#domain").find(":selected").val() + '::' + $("#subject").find(":selected").val() + '::' + $("#focusarea").find(":selected").val());
}
}
else {
return (this.$el.find(":selected").val());
}
}
});
})(jQuery, _, window, document);

Answers (1)