ApplicationImpl cleanup, part 1:
[chromium-blink-merge.git] / third_party / polymer / v1_0 / components-chromium / iron-validatable-behavior / iron-validatable-behavior-extracted.js
blob81e175e92a603ac3d3f038070bc5ed289ef05d70
3 /**
4 * Use `Polymer.IronValidatableBehavior` to implement an element that validates user input.
6 * ### Accessiblity
8 * Changing the `invalid` property, either manually or by calling `validate()` will update the
9 * `aria-invalid` attribute.
11 * @demo demo/index.html
12 * @polymerBehavior
14 Polymer.IronValidatableBehavior = {
16 properties: {
18 /**
19 * Namespace for this validator.
21 validatorType: {
22 type: String,
23 value: 'validator'
26 /**
27 * Name of the validator to use.
29 validator: {
30 type: String
33 /**
34 * True if the last call to `validate` is invalid.
36 invalid: {
37 notify: true,
38 reflectToAttribute: true,
39 type: Boolean,
40 value: false
43 _validatorMeta: {
44 type: Object
49 observers: [
50 '_invalidChanged(invalid)'
53 get _validator() {
54 return this._validatorMeta && this._validatorMeta.byKey(this.validator);
57 ready: function() {
58 this._validatorMeta = new Polymer.IronMeta({type: this.validatorType});
61 _invalidChanged: function() {
62 if (this.invalid) {
63 this.setAttribute('aria-invalid', 'true');
64 } else {
65 this.removeAttribute('aria-invalid');
69 /**
70 * @return {boolean} True if the validator `validator` exists.
72 hasValidator: function() {
73 return this._validator != null;
76 /**
77 * @param {Object} values Passed to the validator's `validate()` function.
78 * @return {boolean} True if `values` is valid.
80 validate: function(values) {
81 var valid = true;
82 if (this.hasValidator()) {
83 valid = this._validator.validate(values);
86 this.invalid = !valid;
87 return valid;