4 * Use `Polymer.IronValidatableBehavior` to implement an element that validates user input.
8 * Changing the `invalid` property, either manually or by calling `validate()` will update the
9 * `aria-invalid` attribute.
11 * @demo demo/index.html
14 Polymer.IronValidatableBehavior = {
19 * Namespace for this validator.
27 * Name of the validator to use.
34 * True if the last call to `validate` is invalid.
38 reflectToAttribute: true,
50 '_invalidChanged(invalid)'
54 return this._validatorMeta && this._validatorMeta.byKey(this.validator);
58 this._validatorMeta = new Polymer.IronMeta({type: this.validatorType});
61 _invalidChanged: function() {
63 this.setAttribute('aria-invalid', 'true');
65 this.removeAttribute('aria-invalid');
70 * @return {boolean} True if the validator `validator` exists.
72 hasValidator: function() {
73 return this._validator != null;
77 * Returns true if the `value` is valid, and updates `invalid`. If you want
78 * your element to have custom validation logic, do not override this method;
79 * override `_getValidity(value)` instead.
81 * @param {Object} value The value to be validated. By default, it is passed
82 * to the validator's `validate()` function, if a validator is set.
83 * @return {boolean} True if `value` is valid.
85 validate: function(value) {
86 this.invalid = !this._getValidity(value);
91 * Returns true if `value` is valid. By default, it is passed
92 * to the validator's `validate()` function, if a validator is set. You
93 * should override this method if you want to implement custom validity
94 * logic for your element.
96 * @param {Object} value The value to be validated.
97 * @return {boolean} True if `value` is valid.
100 _getValidity: function(value) {
101 if (this.hasValidator()) {
102 return this._validator.validate(value);