OLD | NEW |
1 | 1 /** |
2 | |
3 /** | |
4 * Use `Polymer.IronValidatableBehavior` to implement an element that validate
s user input. | 2 * Use `Polymer.IronValidatableBehavior` to implement an element that validate
s user input. |
5 * | 3 * |
6 * ### Accessiblity | 4 * ### Accessibility |
7 * | 5 * |
8 * Changing the `invalid` property, either manually or by calling `validate()`
will update the | 6 * Changing the `invalid` property, either manually or by calling `validate()`
will update the |
9 * `aria-invalid` attribute. | 7 * `aria-invalid` attribute. |
10 * | 8 * |
11 * @demo demo/index.html | 9 * @demo demo/index.html |
12 * @polymerBehavior | 10 * @polymerBehavior |
13 */ | 11 */ |
14 Polymer.IronValidatableBehavior = { | 12 Polymer.IronValidatableBehavior = { |
15 | 13 |
16 properties: { | 14 properties: { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 }, | 65 }, |
68 | 66 |
69 /** | 67 /** |
70 * @return {boolean} True if the validator `validator` exists. | 68 * @return {boolean} True if the validator `validator` exists. |
71 */ | 69 */ |
72 hasValidator: function() { | 70 hasValidator: function() { |
73 return this._validator != null; | 71 return this._validator != null; |
74 }, | 72 }, |
75 | 73 |
76 /** | 74 /** |
77 * @param {Object} values Passed to the validator's `validate()` function. | 75 * Returns true if the `value` is valid, and updates `invalid`. If you want |
78 * @return {boolean} True if `values` is valid. | 76 * your element to have custom validation logic, do not override this method
; |
| 77 * override `_getValidity(value)` instead. |
| 78 |
| 79 * @param {Object} value The value to be validated. By default, it is passed |
| 80 * to the validator's `validate()` function, if a validator is set. |
| 81 * @return {boolean} True if `value` is valid. |
79 */ | 82 */ |
80 validate: function(values) { | 83 validate: function(value) { |
81 var valid = true; | 84 this.invalid = !this._getValidity(value); |
| 85 return !this.invalid; |
| 86 }, |
| 87 |
| 88 /** |
| 89 * Returns true if `value` is valid. By default, it is passed |
| 90 * to the validator's `validate()` function, if a validator is set. You |
| 91 * should override this method if you want to implement custom validity |
| 92 * logic for your element. |
| 93 * |
| 94 * @param {Object} value The value to be validated. |
| 95 * @return {boolean} True if `value` is valid. |
| 96 */ |
| 97 |
| 98 _getValidity: function(value) { |
82 if (this.hasValidator()) { | 99 if (this.hasValidator()) { |
83 valid = this._validator.validate(values); | 100 return this._validator.validate(value); |
84 } | 101 } |
85 | 102 return true; |
86 this.invalid = !valid; | |
87 return valid; | |
88 } | 103 } |
89 | 104 }; |
90 }; | |
91 | |
OLD | NEW |