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

Commit

Permalink
Merge pull request #12 from PolymerElements/fix-validate-api
Browse files Browse the repository at this point in the history
refactor the validation api
  • Loading branch information
notwaldorf committed Aug 5, 2015
2 parents 714ac9f + 3ccf697 commit 2cf754f
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions iron-validatable-behavior.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* Use `Polymer.IronValidatableBehavior` to implement an element that validates user input.
*
* ### Accessiblity
* ### Accessibility
*
* Changing the `invalid` property, either manually or by calling `validate()` will update the
* `aria-invalid` attribute.
Expand Down Expand Up @@ -87,19 +87,35 @@
},

/**
* @param {Object} values Passed to the validator's `validate()` function.
* @return {boolean} True if `values` is valid.
* Returns true if the `value` is valid, and updates `invalid`. If you want
* your element to have custom validation logic, do not override this method;
* override `_getValidity(value)` instead.
* @param {Object} value The value to be validated. By default, it is passed
* to the validator's `validate()` function, if a validator is set.
* @return {boolean} True if `value` is valid.
*/
validate: function(value) {
this.invalid = !this._getValidity(value);
return !this.invalid;
},

/**
* Returns true if `value` is valid. By default, it is passed
* to the validator's `validate()` function, if a validator is set. You
* should override this method if you want to implement custom validity
* logic for your element.
*
* @param {Object} value The value to be validated.
* @return {boolean} True if `value` is valid.
*/
validate: function(values) {
var valid = true;

_getValidity: function(value) {
if (this.hasValidator()) {
valid = this._validator.validate(values);
return this._validator.validate(value);
}

this.invalid = !valid;
return valid;
return true;
}

};

</script>

0 comments on commit 2cf754f

Please sign in to comment.