diff --git a/CHANGELOG.md b/CHANGELOG.md index fe30d98..de07633 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +HEAD +---- + +- new option added: `triggerChange` + 1.2.2 ----- diff --git a/examples/index.html b/examples/index.html index a1163c1..183cfe4 100755 --- a/examples/index.html +++ b/examples/index.html @@ -386,6 +386,10 @@

How about star ratings?

silent: false
Supress callbacks when controlling ratings programatically.

+

+ triggerChange: true
+ Trigger change event on the select field when ratings are set or reset. +

diff --git a/jquery.barrating.js b/jquery.barrating.js index da88d4a..297a851 100644 --- a/jquery.barrating.js +++ b/jquery.barrating.js @@ -213,7 +213,9 @@ // change selected option findOption(value).prop('selected', true); - self.$elem.change(); + if (getData('userOptions').triggerChange) { + self.$elem.change(); + } }; // reset select field @@ -222,7 +224,9 @@ return this.defaultSelected; }); - self.$elem.change(); + if (getData('userOptions').triggerChange) { + self.$elem.change(); + } }; // display the currently selected rating @@ -572,6 +576,7 @@ fastClicks:true, // remove 300ms click delay on touch devices? hoverState:true, // change state on hover? silent:false, // supress callbacks when controlling ratings programatically + triggerChange:true, // trigger change event when ratings are set or reset onSelect:function (value, text, event) { }, // callback fired when a rating is selected onClear:function (value, text) { diff --git a/test/jquery.barrating-spec.js b/test/jquery.barrating-spec.js index 90fe3e2..6f9418b 100644 --- a/test/jquery.barrating-spec.js +++ b/test/jquery.barrating-spec.js @@ -39,6 +39,7 @@ describe('bar rating plugin on init with custom options', function () { expect(BarRating.options.fastClicks).to.equal(true); expect(BarRating.options.hoverState).to.equal(true); expect(BarRating.options.silent).to.equal(false); + expect(BarRating.options.triggerChange).to.equal(true); }); }); @@ -417,10 +418,15 @@ describe('bar rating plugin on destroy', function () { describe('bar rating plugin on set value', function () { var valuesFromCallback = []; + var changeCount = 0; before(function () { createSelect(); + $('#rating').change(function () { + changeCount++; + }); + $('#rating').barrating('show', { onSelect:function (value, text) { valuesFromCallback.push(value, text); @@ -448,6 +454,10 @@ describe('bar rating plugin on set value', function () { expect(valuesFromCallback[1]).to.equal('rating-text-3'); }); + it('should trigger change event on the select field', function () { + expect(changeCount).to.equal(1); + }); + });