iron-validator-behavior

WebJar for iron-validator-behavior

License

License

BSD 3-Clause
GroupId

GroupId

org.webjars.bowergithub.polymerelements
ArtifactId

ArtifactId

iron-validator-behavior
Last Version

Last Version

2.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

iron-validator-behavior
WebJar for iron-validator-behavior
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/PolymerElements/iron-validator-behavior

Download iron-validator-behavior

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.bowergithub.polymerelements/iron-validator-behavior/ -->
<dependency>
    <groupId>org.webjars.bowergithub.polymerelements</groupId>
    <artifactId>iron-validator-behavior</artifactId>
    <version>2.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.bowergithub.polymerelements/iron-validator-behavior/
implementation 'org.webjars.bowergithub.polymerelements:iron-validator-behavior:2.1.0'
// https://jarcasting.com/artifacts/org.webjars.bowergithub.polymerelements/iron-validator-behavior/
implementation ("org.webjars.bowergithub.polymerelements:iron-validator-behavior:2.1.0")
'org.webjars.bowergithub.polymerelements:iron-validator-behavior:jar:2.1.0'
<dependency org="org.webjars.bowergithub.polymerelements" name="iron-validator-behavior" rev="2.1.0">
  <artifact name="iron-validator-behavior" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.bowergithub.polymerelements', module='iron-validator-behavior', version='2.1.0')
)
libraryDependencies += "org.webjars.bowergithub.polymerelements" % "iron-validator-behavior" % "2.1.0"
[org.webjars.bowergithub.polymerelements/iron-validator-behavior "2.1.0"]

Dependencies

compile (2)

Group / Artifact Type Version
org.webjars.bowergithub.polymerelements : iron-meta jar [1.0.0,3)
org.webjars.bowergithub.polymer : polymer jar [1.9.0,3)

Project Modules

There are no modules declared in this project.

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
org.webjars.bowergithub.polymerelements

Versions

Version
2.1.0
2.0.1
1.0.2