Skip to content
This repository was archived by the owner on Dec 19, 2024. It is now read-only.

Commit 2cf754f

Browse files
committed
Merge pull request #12 from PolymerElements/fix-validate-api
refactor the validation api
2 parents 714ac9f + 3ccf697 commit 2cf754f

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

iron-validatable-behavior.html

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* Use `Polymer.IronValidatableBehavior` to implement an element that validates user input.
1818
*
19-
* ### Accessiblity
19+
* ### Accessibility
2020
*
2121
* Changing the `invalid` property, either manually or by calling `validate()` will update the
2222
* `aria-invalid` attribute.
@@ -87,19 +87,35 @@
8787
},
8888

8989
/**
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.
92111
*/
93-
validate: function(values) {
94-
var valid = true;
112+
113+
_getValidity: function(value) {
95114
if (this.hasValidator()) {
96-
valid = this._validator.validate(values);
115+
return this._validator.validate(value);
97116
}
98-
99-
this.invalid = !valid;
100-
return valid;
117+
return true;
101118
}
102-
103119
};
104120

105121
</script>

0 commit comments

Comments
 (0)