Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap select event parameters

I am using the bootstrap select plugin (http://silviomoreto.github.io/) and I am handling the change event "changed.bs.select" to capture any selection changes. As per the documentation at https://silviomoreto.github.io/bootstrap-select/options/, " this event fires after the select's value has been changed. It passes through event, clickedIndex, newValue, oldValue. "

I would like to understand what the newValue and oldValue represent exactly. Because it is always the case where the new value is true and the oldValue is false.

Here is a fiddle to illustrate my point.

https://jsfiddle.net/muojdbh9/

HTML

<select class="selectpicker">
  <option>Mustard</option>
  <option>Ketchup</option>
  <option>Relish</option>
</select>

<div class="res">
Waiting for a change event
</div>

jQuery

$(".selectpicker").on('changed.bs.select', function (event, clickedIndex, newValue, oldValue) {
    $("div.res").html("newValue: " + newValue + "<BR>oldValue: " + oldValue);
});
like image 865
Alexander Avatar asked Feb 11 '16 20:02

Alexander


1 Answers

If you like to have expected behaviour simply change

that.$element.trigger('changed.bs.select', [clickedIndex, $option.prop('selected'), state]);

to

that.$element.trigger('changed.bs.select', [clickedIndex, $option.prop('value'), prevValue]);

in your bootstrap-select.js

like image 198
Pascal Avatar answered Oct 02 '22 14:10

Pascal