3.0.1 • Published 7 years ago
@polymer/iron-validator-behavior v3.0.1
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-behaviorIn 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-cliRunning the demo locally
polymer serve --npm
open http://127.0.0.1:<port>/demo/Running the tests
polymer test --npm3.0.1
7 years ago
3.0.0
7 years ago
3.0.0-pre.26
7 years ago
3.0.0-pre.25
7 years ago
3.0.0-pre.24
7 years ago
3.0.0-pre.23
7 years ago
3.0.0-pre.22
7 years ago
3.0.0-pre.21
7 years ago
3.0.0-pre.20
7 years ago
3.0.0-pre.19
7 years ago
3.0.0-pre.18
7 years ago
3.0.0-pre.17
7 years ago
3.0.0-pre.16
7 years ago
3.0.0-pre.15
8 years ago
3.0.0-pre.14
8 years ago
3.0.0-pre.13
8 years ago
3.0.0-pre.12
8 years ago
3.0.0-pre.11
8 years ago
3.0.0-pre.10
8 years ago
3.0.0-pre.8
8 years ago
3.0.0-pre.7
8 years ago
3.0.0-pre.6
8 years ago
3.0.0-pre.4
8 years ago
3.0.0-pre.3
8 years ago
3.0.0-pre.2
8 years ago
3.0.0-pre.1
8 years ago
1.0.1-pre.3
9 years ago
1.0.1-pre.2
9 years ago
1.0.1-pre.1
9 years ago
0.0.4
9 years ago
0.0.3
10 years ago
0.0.1
10 years ago