JSPM

  • Created
  • Published
  • Downloads 28862
  • Score
    100M100P100Q174012F
  • License BSD-3-Clause

Provides a behavior for an element that validates user input

Package Exports

  • @polymer/iron-validatable-behavior/iron-validatable-behavior.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@polymer/iron-validatable-behavior) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Build status

Demo and API docs

Polymer.IronValidatableBehavior

Use Polymer.IronValidatableBehavior to implement an element that validates user input. Use the related Polymer.IronValidatorBehavior to add custom validation logic to an iron-input.

By default, an <iron-form> element validates its fields when the user presses the submit button. To validate a form imperatively, call the form's validate() method, which in turn will call validate() on all its children. By using Polymer.IronValidatableBehavior, your custom element will get a public validate(), which will return the validity of the element, and a corresponding invalid attribute, which can be used for styling.

To implement the custom validation logic of your element, you must override the protected _getValidity() method of this behaviour, rather than validate(). See this for an example.

Changes in 2.0

  • validate() no longer requires a value parameter to be passed, and will use the element's value property if it exists
  • validatorType and validatorName were unused and have been removed

Accessibility

Changing the invalid property, either manually or by calling validate() will update the aria-invalid attribute.