Skip to content

Commit

Permalink
fix(...) input validations (#958)
Browse files Browse the repository at this point in the history
1. For paper-input, validate only when its value changes. 
2. For paper-autocomplete, validate only when selection is changed.
  • Loading branch information
xomaczar authored and miguelcobain committed Jul 25, 2018
1 parent 19df96a commit 9a840b9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions addon/components/paper-autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ export default PowerSelect.extend(ValidationMixin, ChildMixin, {
this._super(...arguments);
},

updateSelection() {
this._super(...arguments);
this.notifyValidityChange();
},

actions: {

onTriggerMouseDown() {
Expand Down
10 changes: 9 additions & 1 deletion addon/components/paper-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,14 @@ export default Component.extend(FocusableMixin, ColorMixin, ChildMixin, Validati
didReceiveAttrs() {
this._super(...arguments);
assert('{{paper-input}} requires an `onChange` action or null for no action.', this.get('onChange') !== undefined);
this.notifyValidityChange();

let { value, errors } = this.getProperties('value', 'errors');
let { _prevValue, _prevErrors } = this.getProperties('_prevValue', '_prevErrors');
if (value !== _prevValue || errors !== _prevErrors) {
this.notifyValidityChange();
}
this._prevValue = value;
this._prevErrors = errors;
},

didInsertElement() {
Expand Down Expand Up @@ -160,6 +167,7 @@ export default Component.extend(FocusableMixin, ColorMixin, ChildMixin, Validati
},

handleBlur(e) {

this.sendAction('onBlur', e);
this.set('isTouched', true);
this.notifyValidityChange();
Expand Down
5 changes: 3 additions & 2 deletions tests/integration/components/paper-form-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Component from '@ember/component';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, triggerEvent, click } from '@ember/test-helpers';
import { render, triggerEvent, click, blur } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';

module('Integration | Component | paper form', function(hooks) {
Expand Down Expand Up @@ -110,7 +110,8 @@ module('Integration | Component | paper form', function(hooks) {
assert.notOk(isInvalidAndTouched);
});

this.$('input:first').trigger('blur');
await click('input:first-of-type');
await blur('input:first-of-type');

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

0 comments on commit 9a840b9

Please sign in to comment.