Skip to content

Commit

Permalink
Fix for "change" event being fired when value doesn't change (#175).
Browse files Browse the repository at this point in the history
  • Loading branch information
brianreavis committed Nov 3, 2013
1 parent 25425e7 commit 54cc373
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/selectize.js
Original file line number Diff line number Diff line change
Expand Up @@ -1226,10 +1226,10 @@ $.extend(Selectize.prototype, {
var i, active, options, value_next;
value = hash_key(value);

if (inputMode === 'single') self.clear();
if (inputMode === 'multi' && self.isFull()) return;
if (self.items.indexOf(value) !== -1) return;
if (!self.options.hasOwnProperty(value)) return;
if (inputMode === 'single') self.clear();
if (inputMode === 'multi' && self.isFull()) return;

$item = $(self.render('item', self.options[value]));
self.items.splice(self.caretPos, 0, value);
Expand Down
15 changes: 15 additions & 0 deletions test/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ describe('Events', function() {
});
test.selectize.setValue('c');
});
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('change', 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() {
Expand Down

0 comments on commit 54cc373

Please sign in to comment.