Skip to content

Commit

Permalink
trigger onValidityChange when global touched changes
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelcobain committed Mar 6, 2017
1 parent 78b6efb commit 7cb32b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion addon/components/paper-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ export default Component.extend(ParentMixin, {

actions: {
onValidityChange() {
if (this.get('lastIsValid') !== this.get('isValid')) {
if (this.get('lastIsValid') !== this.get('isValid') || this.get('lastIsTouched') !== this.get('isTouched')) {
this.sendAction('onValidityChange', this.get('isValid'), this.get('isTouched'), this.get('isInvalidAndTouched'));
this.set('lastIsValid', this.get('isValid'));
this.set('lastIsTouched', this.get('isTouched'));
}
},
onSubmit() {
Expand Down
12 changes: 9 additions & 3 deletions tests/integration/components/paper-form-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ test('form `onSubmit` action is invoked', function(assert) {
test('form `onValidityChange` action is invoked', function(assert) {
// paper-input triggers `onValidityChange` on render
// so we expect two runs: one on render and another on validity change
assert.expect(6);
assert.expect(9);

this.set('onValidityChange', (isValid, isTouched, isInvalidAndTouched) => {
assert.ok(isValid);
Expand All @@ -80,13 +80,19 @@ test('form `onValidityChange` action is invoked', function(assert) {
`);

this.set('onValidityChange', (isValid, isTouched, isInvalidAndTouched) => {
assert.notOk(isValid);
assert.ok(isValid);
assert.ok(isTouched);
assert.ok(isInvalidAndTouched);
assert.notOk(isInvalidAndTouched);
});

this.$('input:first').trigger('blur');

this.set('onValidityChange', (isValid, isTouched, isInvalidAndTouched) => {
assert.notOk(isValid);
assert.ok(isTouched);
assert.ok(isInvalidAndTouched);
});

this.set('errors', [{
message: 'foo should be a number.',
attribute: 'foo'
Expand Down

0 comments on commit 7cb32b0

Please sign in to comment.