Boot Options

I use the bootstrap select plugin ( http://silviomoreto.imtqy.com/ ) and I handle the change event "changed.bs.select" to capture any selection changes. According to the documentation at https://silviomoreto.imtqy.com/bootstrap-select/options/ , this event fires after the selection value changes. It goes through the event, clickedIndex, newValue, oldValue.

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

Here is a script illustrating 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);
});
+4
4

. , newValue oldValue , . newValue oldValue . , , .

true , false .

, :

newValue: true oldValue: false

, :

newValue: false oldValue: true .

caseyjhol:

https://github.com/silviomoreto/bootstrap-select/issues/1378/#issuecomment-216393099

+3

,

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

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

bootstrap-select.js

+4

newValue "selected", oldValue "selected". , , true false . , bootstrap select - , , , "" .

+2

. TAGraves , . :

JQuery

$(".selectpicker").on('changed.bs.select', function (event, clickedIndex, newValue, oldValue) {
    var Value = $(".selectpicker option:selected").val()
});
+1

Source: https://habr.com/ru/post/1628374/


All Articles