Amit Saha
Amit Saha

Reputation: 61

How to fire an event on close of drop down in Bootstrap select with multiple selection in Backbone.js

I am using bootstrap select with multiple selection in an application using Backbone.js . Now I want to fire an event when all the selection is done and drop down closes. change event will fire on every selection which I don't want.

My code is below

    var agentMetricView = ParentView.extend({

		events: {
			'mouseup .js-table-agent': 'adjustAgentTable',
			'change .js-select': 'changeDropdown',
		},
      
		changeDropdown: function(event) {
			debugger;
			/*this.selectedSkill = $("#skill-agent").find("option:selected").text();*/
			console.log($(event.currentTarget.id).val());
		}
      
    	});

	return agentMetricView;
 <span class="dropdown-text">Dept:</span>
      <select  class="selectpicker left_float js-select" data-select="selectedDept" multiple data-hide-disabled="true" data-size="5" data-style="btn-primary" data-width="120px">
         <option>Option 1</option>
         <option>Option 2</option>
         <option>Option 3</option>
         <option>Option 4</option>
      </select>

silviomoreto has provided an option but i don't know how to use it in Backbone

$selectpicker.on('hidden.bs.dropdown', function() {
    console.log('hide');
});

check Bootstrap-Select issue #216 Change Event

When I add the below event listener it does not fire

'hide.bs.dropdown .selectpicker ': 'changeDropdown',

Upvotes: 0

Views: 5161

Answers (2)

pranav shinde
pranav shinde

Reputation: 1650

This works for me:

$('#yourid').on('hide.bs.select', function (e) {alert('test');});

Upvotes: 1

Amit Saha
Amit Saha

Reputation: 61

I found the solution although the actual reason I am not clear about. The problem is with using bootstrap class ".selectpicker" when I am using my own custom class ".js-select" it is working. This seems to be the answer

'hide.bs.dropdown .js-select': 'changeDropdown',

instead of this

'hide.bs.dropdown .selectpicker ': 'changeDropdown',

Reason I have no idea I some one tells I will be happy to know.

Upvotes: 0

Related Questions