Well, my answer may not be the "Polymer way", but it works and is a more "traditional programmatic" way.
A short list of ideas for this solution:
- input into the document, as well as search in hardware, look at the value of the validator attribute in the global iron-meta object.
- Each Polymer.IronValidatorBehavior has a name (validatorName), type ('validator') and a validation function
- Each Polymer.IronValidatorBehavior is registered in the corresponding "validator" list in the iron-meta object li>
So this is the short code I got from the above points:
var validator = { validatorName: 'my-custom-validator', validatorType: 'validator', validate: function(value) { ...my validation code... } }; new Polymer.IronMeta({ type: validator.validatorType, key: validator.validatorName, value: validator });
You can put this code in any attached or created event handler. But run it before any check is done, of course ...
Then you can write
<paper-input validator="my-custom-validator"></paper-input>
If you want to check if your validator is registered at the entrance, go down the dom-tree in any dev-tool and press: $0.hasValidator() and $0.validator to check if your validator has been successfully registered at the entrance.
Kjell
source share