Skip to content

Commit

Permalink
Add triggerChange option
Browse files Browse the repository at this point in the history
  • Loading branch information
antennaio committed Feb 19, 2017
1 parent 28ecb90 commit 923992a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,8 @@
HEAD
----

- new option added: `triggerChange`

1.2.2
-----

Expand Down
4 changes: 4 additions & 0 deletions examples/index.html
Expand Up @@ -386,6 +386,10 @@ <h1>How about star ratings?</h1>
<strong>silent: false</strong><br>
Supress callbacks when controlling ratings programatically.
</p>
<p>
<strong>triggerChange: true</strong><br>
Trigger change event on the select field when ratings are set or reset.
</p>
</div>
</div>

Expand Down
9 changes: 7 additions & 2 deletions jquery.barrating.js
Expand Up @@ -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
Expand All @@ -222,7 +224,9 @@
return this.defaultSelected;
});

self.$elem.change();
if (getData('userOptions').triggerChange) {
self.$elem.change();
}
};

// display the currently selected rating
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions test/jquery.barrating-spec.js
Expand Up @@ -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);
});

});
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});

});


Expand Down

0 comments on commit 923992a

Please sign in to comment.