Directory

← Back

iron-validator-behavior

Implements a custom input or form validator

Author

Rating

Popularity

<100

Published on NPM Build status Published on webcomponents.org

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

Compatibility

(Loading compatibility data...)

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 validator iron-validator-behavior - Vaadin Add-on Directory
[![Published on NPM](https://img.shields.io/npm/v/@polymer/iron-validator-behavior.svg)](https://www.npmjs.com/package/@polymer/iron-validator-behavior) [![Build status](https://travis-ci.org/PolymerElements/iron-validator-behavior.svg?branch=master)](https://travis-ci.org/PolymerElements/iron-validator-behavior) [![Published on webcomponents.org](https://img.shields.io/badge/webcomponents.org-published-blue.svg)](https://webcomponents.org/element/@polymer/iron-validator-behavior) ## 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](https://www.webcomponents.org/element/@polymer/iron-validator-behavior), [Demo](https://www.webcomponents.org/element/@polymer/iron-validator-behavior/demo/demo/index.html). ## Usage ### Installation ``` npm install --save @polymer/iron-validator-behavior ``` ### In a Polymer 3 element that is a validator ```js 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 ``` ## Contributing If you want to send a PR to this element, here are the instructions for running the tests and demo locally: ### Installation ```sh git clone https://github.com/PolymerElements/iron-validator-behavior cd iron-validator-behavior npm install npm install -g polymer-cli ``` ### Running the demo locally ```sh polymer serve --npm open http://127.0.0.1:/demo/ ``` ### Running the tests ```sh polymer test --npm ```
Documentation
Online 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

Online