iron-validator-behavior
Implements a custom input or form validator
IronValidatorBehavior
Use IronValidatorBehavior
to implement a custom input/form validator. Element
instances implementing this behavior will be registered for use in elements that implement
IronValidatableBehavior
.
See: Documentation, Demo.
Usage
Installation
npm install --save @polymer/iron-validator-behavior
In a Polymer 3 element that is a validator
import {PolymerElement, html} from '@polymer/polymer';
import {mixinBehaviors} from '@polymer/polymer/lib/legacy/class.js';
import {IronValidatorBehavior} from '@polymer/iron-validator-behavior/iron-validator-behavior.js';
class SampleValidator extends mixinBehaviors([IronValidatorBehavior], PolymerElement){
// This validator only validates strings, and is only valid if
// the value is "cat".
function validate(value) {
return value === 'cat';
}
}
customElements.define('sample-validator', SampleValidator);
Using this validator element in an html file
<html>
<head>
<script type="module">
import '../sample-validator.js';
</script>
</head>
<body>
<sample-validator id="aValidator"></sample-validator>
<input id="input">
<script>
input.addEventListener('input', function(event) {
var valid = aValidator.validate(input.value);
if (valid)
input.removeAttribute('invalid');
else
input.setAttribute('invalid', true);
});
</script>
</body>
</html>
Contributing
If you want to send a PR to this element, here are the instructions for running the tests and demo locally:
Installation
git clone https://github.com/PolymerElements/iron-validator-behavior
cd iron-validator-behavior
npm install
npm install -g polymer-cli
Running the demo locally
polymer serve --npm
open http://127.0.0.1:<port>/demo/
Running the tests
polymer test --npm
Links
Compatibility
Was this helpful? Need more help?
Leave a comment or a question below. You can also join
the chat on Discord or
ask questions on StackOverflow.
Version
Dependencies
- @polymer/iron-meta#^3.0.0-pre.26
- @polymer/polymer#^3.0.0
- Released
- 2018-09-14
- Maturity
- IMPORTED
- License
- BSD 3-clause "New" or "Revised" License
Compatibility
- Framework
- Polymer 1.0+
- Polymer 3.0+
- Polymer 2.0+ in 2.1.0
- Browser
- Browser Independent
iron-validator-behavior - Vaadin Add-on Directory
Implements a custom input or form validatorOnline Demo
GitHub Homepage
Issue tracker
View on GitHub
License
View on NPM
iron-validator-behavior version 0.8.0
### Dependencies
* polymer#Polymer/polymer#v0.8.0-rc.7
* iron-meta#PolymerElements/iron-meta#^0.8.0
iron-validator-behavior version 0.9.0
### Dependencies
* polymer#Polymer/polymer#v0.9.0-rc.1
* iron-meta#PolymerElements/iron-meta#^0.9.0
iron-validator-behavior version 0.9.1
### Dependencies
* iron-meta#PolymerElements/iron-meta#^0.9.0
* polymer#Polymer/polymer#^0.9.0
iron-validator-behavior version 0.9.2
### Dependencies
* iron-meta#PolymerElements/iron-meta#^0.9.0
* polymer#Polymer/polymer#^0.9.0
iron-validator-behavior version 1.0.0
### Dependencies
* iron-meta#PolymerElements/iron-meta#^1.0.0
* polymer#Polymer/polymer#^1.0.0
iron-validator-behavior version 1.0.1
### Dependencies
* iron-meta#PolymerElements/iron-meta#^1.0.0
* polymer#Polymer/polymer#^1.0.0
iron-validator-behavior version 0.0.1
### Dependencies
* @polymer/iron-meta#^0.0.1
* @polymer/polymer#^1.2.5-npm-test.2
iron-validator-behavior version 0.0.3
### Dependencies
* @polymer/iron-meta#^0.0.3
* @polymer/polymer#^1.2.5-npm-test.2
iron-validator-behavior version 1.0.2
### Dependencies
* iron-meta#PolymerElements/iron-meta#^1.0.0
* polymer#Polymer/polymer#^1.0.0
iron-validator-behavior version 2.0.0
### Dependencies
* iron-meta#PolymerElements/iron-meta#1 - 2
* polymer#Polymer/polymer#1.9 - 2
iron-validator-behavior version 3.0.0-pre.1
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.1
* @polymer/polymer#^3.0.0-pre.1
iron-validator-behavior version 3.0.0-pre.2
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.1
* @polymer/polymer#^3.0.0-pre.1
iron-validator-behavior version 3.0.0-pre.3
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.3
* @polymer/polymer#^3.0.0-pre.3
iron-validator-behavior version 3.0.0-pre.4
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.4
* @polymer/polymer#^3.0.0-pre.4
iron-validator-behavior version 2.0.1
### Dependencies
* iron-meta#PolymerElements/iron-meta#1 - 2
* polymer#Polymer/polymer#1.9 - 2
iron-validator-behavior version 3.0.0-pre.6
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.6
* @polymer/polymer#^3.0.0-pre.6
iron-validator-behavior version 3.0.0-pre.7
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.7
* @polymer/polymer#^3.0.0-pre.7
iron-validator-behavior version 3.0.0-pre.8
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.7
* @polymer/polymer#^3.0.0-pre.7
iron-validator-behavior version 2.1.0
### Dependencies
* iron-meta#PolymerElements/iron-meta#1 - 2
* polymer#Polymer/polymer#1.9 - 2
iron-validator-behavior version 3.0.0-pre.10
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.10
* @polymer/polymer#^3.0.0-pre.10
iron-validator-behavior version 3.0.0-pre.11
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.10
* @polymer/polymer#^3.0.0-pre.10
iron-validator-behavior version 3.0.0-pre.12
### Dependencies
* @polymer/iron-meta#3.0.0-pre.12
* @polymer/polymer#3.0.0-pre.12
iron-validator-behavior version 3.0.0-pre.13
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.13
* @polymer/polymer#^3.0.0-pre.13
iron-validator-behavior version 3.0.0-pre.14
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.14
* @polymer/polymer#^3.0.0-pre.13
iron-validator-behavior version 3.0.0-pre.15
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.15
* @polymer/polymer#^3.0.0-pre.13
iron-validator-behavior version 3.0.0-pre.16
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.16
* @polymer/polymer#^3.0.0-pre.13
iron-validator-behavior version 3.0.0-pre.17
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.17
* @polymer/polymer#^3.0.0-pre.13
iron-validator-behavior version 3.0.0-pre.18
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.18
* @polymer/polymer#^3.0.0
iron-validator-behavior version 3.0.0-pre.19
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.19
* @polymer/polymer#^3.0.0
iron-validator-behavior version 3.0.0-pre.20
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.20
* @polymer/polymer#^3.0.0
iron-validator-behavior version 3.0.0-pre.21
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.21
* @polymer/polymer#^3.0.0
iron-validator-behavior version 3.0.0-pre.22
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.20
* @polymer/polymer#^3.0.0
iron-validator-behavior version 3.0.0-pre.23
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.22
* @polymer/polymer#^3.0.0
iron-validator-behavior version 3.0.0-pre.24
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.22
* @polymer/polymer#^3.0.0
iron-validator-behavior version 3.0.0-pre.25
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.24
* @polymer/polymer#^3.0.0
iron-validator-behavior version 3.0.0-pre.26
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.25
* @polymer/polymer#^3.0.0
iron-validator-behavior version 3.0.0
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.26
* @polymer/polymer#^3.0.0
iron-validator-behavior version 3.0.1
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.26
* @polymer/polymer#^3.0.0