|
16 | 16 | /** |
17 | 17 | * Use `Polymer.IronValidatableBehavior` to implement an element that validates user input. |
18 | 18 | * |
19 | | - * ### Accessiblity |
| 19 | + * ### Accessibility |
20 | 20 | * |
21 | 21 | * Changing the `invalid` property, either manually or by calling `validate()` will update the |
22 | 22 | * `aria-invalid` attribute. |
|
87 | 87 | }, |
88 | 88 |
|
89 | 89 | /** |
90 | | - * @param {Object} values Passed to the validator's `validate()` function. |
91 | | - * @return {boolean} True if `values` is valid. |
| 90 | + * Returns true if the `value` is valid, and updates `invalid`. If you want |
| 91 | + * your element to have custom validation logic, do not override this method; |
| 92 | + * override `_getValidity(value)` instead. |
| 93 | +
|
| 94 | + * @param {Object} value The value to be validated. By default, it is passed |
| 95 | + * to the validator's `validate()` function, if a validator is set. |
| 96 | + * @return {boolean} True if `value` is valid. |
| 97 | + */ |
| 98 | + validate: function(value) { |
| 99 | + this.invalid = !this._getValidity(value); |
| 100 | + return !this.invalid; |
| 101 | + }, |
| 102 | + |
| 103 | + /** |
| 104 | + * Returns true if `value` is valid. By default, it is passed |
| 105 | + * to the validator's `validate()` function, if a validator is set. You |
| 106 | + * should override this method if you want to implement custom validity |
| 107 | + * logic for your element. |
| 108 | + * |
| 109 | + * @param {Object} value The value to be validated. |
| 110 | + * @return {boolean} True if `value` is valid. |
92 | 111 | */ |
93 | | - validate: function(values) { |
94 | | - var valid = true; |
| 112 | + |
| 113 | + _getValidity: function(value) { |
95 | 114 | if (this.hasValidator()) { |
96 | | - valid = this._validator.validate(values); |
| 115 | + return this._validator.validate(value); |
97 | 116 | } |
98 | | - |
99 | | - this.invalid = !valid; |
100 | | - return valid; |
| 117 | + return true; |
101 | 118 | } |
102 | | - |
103 | 119 | }; |
104 | 120 |
|
105 | 121 | </script> |
0 commit comments