iron-validatable-behavior
Implements an element validated with Polymer.IronValidatorBehavior
IronValidatableBehavior
Use IronValidatableBehavior
to implement an element that validates user input. By using this behaviour, your custom element will get a public validate()
method, which
will return the validity of the element, and a corresponding invalid
attribute,
which can be used for styling. Can be used alongside an element implementing
the IronValidatableBehavior
behaviour.
See: Documentation, Demo.
Usage
Installation
npm install --save @polymer/iron-validatable-behavior
In a Polymer 3 element
import {PolymerElement, html} from '@polymer/polymer';
import {mixinBehaviors} from '@polymer/polymer/lib/legacy/class.js';
import {IronValidatableBehavior} from '@polymer/iron-validatable-behavior/iron-validatable-behavior.js';
class SampleElement extends mixinBehaviors([IronValidatableBehavior], PolymerElement) {
static get template() {
return html`
<style>
:host {
border: 1px solid green;
color: green;
}
:host([invalid]) {
border: 1px solid red;
color: red;
}
</style>
<input id="input">
`;
// Override this method if you want to implement custom validity
// for your element. This element is only valid if the value in the
// input is "cat".
function _getValidity() {
return this.$.input.value === 'cat';
}
}
}
customElements.define('sample-element', SampleElement);
In an html file using the element
<html>
<head>
<script type="module" src="./sample-element.js"></script>
</head>
<body>
<sample-element id="el"></sample-element>
<button onclick="el.validate()">Validate!</button>
</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-validatable-behavior
cd iron-validatable-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-validatable-behavior - Vaadin Add-on Directory
Implements an element validated with Polymer.IronValidatorBehaviorIssue tracker
License
View on NPM
View on GitHub
Online Demo
Documentation
iron-validatable-behavior version 0.8.0
### Dependencies
* polymer#Polymer/polymer#v0.8.0-rc.7
* iron-meta#PolymerElements/iron-meta#^0.8.0
iron-validatable-behavior version 0.9.0
### Dependencies
* polymer#Polymer/polymer#v0.9.0-rc.1
* iron-meta#PolymerElements/iron-meta#^0.9.0
iron-validatable-behavior version 0.9.1
### Dependencies
* iron-meta#PolymerElements/iron-meta#^0.9.0
* polymer#Polymer/polymer#^0.9.0
iron-validatable-behavior version 0.9.2
### Dependencies
* iron-meta#PolymerElements/iron-meta#^0.9.0
* polymer#Polymer/polymer#^0.9.0
iron-validatable-behavior version 1.0.0
### Dependencies
* iron-meta#PolymerElements/iron-meta#^1.0.0
* polymer#Polymer/polymer#^1.0.0
iron-validatable-behavior version 1.0.1
### Dependencies
* iron-meta#PolymerElements/iron-meta#^1.0.0
* polymer#Polymer/polymer#^1.0.0
iron-validatable-behavior version 1.0.2
### Dependencies
* iron-meta#PolymerElements/iron-meta#^1.0.0
* polymer#Polymer/polymer#^1.0.0
iron-validatable-behavior version 1.0.3
### Dependencies
* iron-meta#PolymerElements/iron-meta#^1.0.0
* polymer#Polymer/polymer#^1.0.0
iron-validatable-behavior version 1.0.4
### Dependencies
* iron-meta#PolymerElements/iron-meta#^1.0.0
* polymer#Polymer/polymer#^1.0.0
iron-validatable-behavior version 1.0.5
### Dependencies
* iron-meta#PolymerElements/iron-meta#^1.0.0
* polymer#Polymer/polymer#^1.0.0
iron-validatable-behavior version 0.0.1
### Dependencies
* @polymer/iron-meta#^0.0.1
* @polymer/polymer#^1.2.5-npm-test.2
iron-validatable-behavior version 0.0.3
### Dependencies
* @polymer/iron-meta#^0.0.3
* @polymer/polymer#^1.2.5-npm-test.2
iron-validatable-behavior version 1.1.0
### Dependencies
* iron-meta#PolymerElements/iron-meta#^1.0.0
* polymer#Polymer/polymer#^1.0.0
iron-validatable-behavior version 1.1.1
### Dependencies
* iron-meta#PolymerElements/iron-meta#^1.0.0
* polymer#Polymer/polymer#^1.0.0
iron-validatable-behavior version 1.1.2
### Dependencies
* iron-meta#PolymerElements/iron-meta#^1.0.0
* polymer#Polymer/polymer#^1.0.0
iron-validatable-behavior version 2.0.0
### Dependencies
* iron-meta#PolymerElements/iron-meta#1 - 2
* polymer#Polymer/polymer#1.9 - 2
iron-validatable-behavior version 3.0.0-pre.1
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.1
* @polymer/polymer#^3.0.0-pre.1
iron-validatable-behavior version 3.0.0-pre.2
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.1
* @polymer/polymer#^3.0.0-pre.1
iron-validatable-behavior version 3.0.0-pre.3
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.3
* @polymer/polymer#^3.0.0-pre.3
iron-validatable-behavior version 3.0.0-pre.4
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.4
* @polymer/polymer#^3.0.0-pre.4
iron-validatable-behavior version 3.0.0-pre.6
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.6
* @polymer/polymer#^3.0.0-pre.6
iron-validatable-behavior version 3.0.0-pre.7
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.7
* @polymer/polymer#^3.0.0-pre.7
iron-validatable-behavior version 3.0.0-pre.8
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.7
* @polymer/polymer#^3.0.0-pre.7
iron-validatable-behavior version 2.1.0
### Dependencies
* iron-meta#PolymerElements/iron-meta#1 - 2
* polymer#Polymer/polymer#1.9 - 2
iron-validatable-behavior version 3.0.0-pre.10
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.10
* @polymer/polymer#^3.0.0-pre.10
iron-validatable-behavior version 3.0.0-pre.11
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.10
* @polymer/polymer#^3.0.0-pre.10
iron-validatable-behavior version 3.0.0-pre.12
### Dependencies
* @polymer/iron-meta#3.0.0-pre.12
* @polymer/polymer#3.0.0-pre.12
iron-validatable-behavior version 3.0.0-pre.13
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.13
* @polymer/polymer#^3.0.0-pre.13
iron-validatable-behavior version 3.0.0-pre.14
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.14
* @polymer/polymer#^3.0.0-pre.13
iron-validatable-behavior version 3.0.0-pre.15
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.15
* @polymer/polymer#^3.0.0-pre.13
iron-validatable-behavior version 3.0.0-pre.16
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.16
* @polymer/polymer#^3.0.0-pre.13
iron-validatable-behavior version 3.0.0-pre.17
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.17
* @polymer/polymer#^3.0.0-pre.13
iron-validatable-behavior version 3.0.0-pre.18
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.18
* @polymer/polymer#^3.0.0
iron-validatable-behavior version 3.0.0-pre.19
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.19
* @polymer/polymer#^3.0.0
iron-validatable-behavior version 3.0.0-pre.20
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.20
* @polymer/polymer#^3.0.0
iron-validatable-behavior version 3.0.0-pre.21
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.21
* @polymer/polymer#^3.0.0
iron-validatable-behavior version 3.0.0-pre.22
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.20
* @polymer/polymer#^3.0.0
iron-validatable-behavior version 3.0.0-pre.23
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.22
* @polymer/polymer#^3.0.0
iron-validatable-behavior version 3.0.0-pre.24
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.22
* @polymer/polymer#^3.0.0
iron-validatable-behavior version 3.0.0-pre.25
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.24
* @polymer/polymer#^3.0.0
iron-validatable-behavior version 3.0.0-pre.26
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.25
* @polymer/polymer#^3.0.0
iron-validatable-behavior version 3.0.0
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.26
* @polymer/polymer#^3.0.0
iron-validatable-behavior version 3.0.1
### Dependencies
* @polymer/iron-meta#^3.0.0-pre.26
* @polymer/polymer#^3.0.0