googlearchive / paper-input

A text input à la Material Design
23 stars 43 forks source link

paper-input-decorator with autoValidate don't watch dataChange for check the invalid status #148

Open jmorille opened 9 years ago

jmorille commented 9 years ago

paper-input-decorator version 0.5.4

Simple use case,

See the sample below

<!DOCTYPE html>
<html>

<head lang="en">
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge"/>

  <meta name="Cache-Control" content="private, must-revalidate"/>

  <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
  <meta name="mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-touch-fullscreen" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style"
        content="black-translucent">
  <meta name="format-detection" content="telephone=no">

  <meta name="application-name" content="Admin App">
  <title>Admin App</title>

  <script src="components/webcomponentsjs/webcomponents.js"></script>

</head>
<body>
<link rel="import" href="components/polymer/polymer.html">

<link rel="import" href="components/paper-button/paper-button.html">
<link rel="import" href="components/core-input/core-input.html">
<link rel="import" href="components/paper-input/paper-input-decorator.html">

<polymer-element name="bug-inputtext-decorator">

  <template>

    <div layout vertical>
      <paper-button on-tap="{{validate}}">
        <span>Validate</span>
      </paper-button>
      <paper-input-decorator id="emailValidator" floatingLabel label="Email" autoValidate>
        <input is="core-input" id="input2" value="{{ data.email}}" type="email" required>
      </paper-input-decorator>

      <paper-button on-tap="{{bug1}}">
        <span>Bug 1: Backend event don't change invalid status</span>
      </paper-button>
      <paper-button on-tap="{{bug2}}">
        <span>Bug 2: Bad email don't display error text from input</span>
      </paper-button>

    </div>
  </template>
  <script>
    Polymer('bug-inputtext-decorator', {
      data: {email: undefined},

      bug1: function () {
        this.data.email = 'toto@toto.com'
      },
      bug2: function () {
        this.data.email = 'toto'
      },
      validate: function () {
        this.$.emailValidator.validate();
      }

    });
  </script>
</polymer-element>

<bug-inputtext-decorator></bug-inputtext-decorator>

</body>
</html>
KrisSiegel commented 9 years ago

Looking at the documentation I believe this is intended. https://www.polymer-project.org/docs/elements/paper-elements.html#paper-input-decorator

This will not validate when changing the input programmatically; call validate() instead.

Which is unfortunate as I just ran into this issue and assumed it would observe and update based on the data changed versus only monitoring for direct user input. I would love to see this behavior changed, however.