Skip to content

Commit

Permalink
Trigger "input" event as per DOM specs [Fixes #1562]
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre authored and risadams committed Dec 2, 2020
1 parent b44f073 commit 5dfe01c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/selectize.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ $.extend(Selectize.prototype, {
* input / select element.
*/
onChange: function() {
this.$input.trigger('input');
this.$input.trigger('change');
},

Expand Down Expand Up @@ -806,8 +807,8 @@ $.extend(Selectize.prototype, {

/**
* Resets the number of max items to the given value
*
* @param {number} value
*
* @param {number} value
*/
setMaxItems: function(value){
if(value === 0) value = null; //reset to unlimited items.
Expand Down Expand Up @@ -1385,7 +1386,7 @@ $.extend(Selectize.prototype, {

/**
* Clears all options.
*
*
* @param {boolean} silent
*/
clearOptions: function(silent) {
Expand Down
32 changes: 31 additions & 1 deletion test/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,36 @@ describe('Events', function() {
});
});

describe('input', function() {
it('should be triggered once before change', function(done) {
var test = setup_test('<select><option value="a" selected></option><option value="b"></option><option value="c"></option></select>', {});
var evt = '';
test.$select.on('change', function() { evt = evt + 'change'; });
test.$select.on('input', function() { evt = evt + 'input'; });
test.selectize.setValue('b');

window.setTimeout(function() {
expect(evt).to.be.equal('inputchange');
done();
}, 0);
});
it('should not be triggered when the selected item has not changed', function(done) {
var test = setup_test('<select><option value="a" selected="selected">a</option></select>');

var counter = 0;
test.$select.on('input', function() { counter++; });

syn.click(test.selectize.$control).delay(0, function() {
syn
.click($('[data-value="a"]', test.selectize.$dropdown))
.delay(0, function() {
expect(counter).to.be.equal(0);
done();
});
});
});
});

describe('item_add', function() {
it('should be triggered', function(done) {
var test = setup_test('<select><option value="a"></option><option value="b"></option><option value="c"></option></select>', {});
Expand Down Expand Up @@ -313,4 +343,4 @@ describe('Events', function() {
});
});

});
});

0 comments on commit 5dfe01c

Please sign in to comment.