简体   繁体   中英

Polymer paper-input validity flag

I'm experimenting with Polymer elements and currently with the paper form elements.

I haven't still managed to find if it is possible to get in a Javascript variable the fact that a paper-form is valid. Any ideas?

I'm using auto-validate.

 <paper-input id="foo"
        name="foo"
        label="Foo"
        required
        auto-validate
        pattern="[A-Za-z0-9]+"
        error-message="Alphanumerical characters only">
 </paper-input>

Thanks a lot!

There is a property on the paper-input element called invalid which you can check to see if the value of the input is valid or not.

For example:

<paper-input id="foo"
  name="foo"
  label="Foo"
  required
  auto-validate
  pattern="[A-Za-z0-9]+"
  invalid="{{invalid}}"
  error-message="Alphanumerical characters only">
</paper-input>

And then in the JavaScript you can call

var invalid = this.$.foo.invalid;

See the docs here for more info.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM