Let Me Tink About It
Let Me Tink About It

Reputation: 16102

Observer not responding to <paper-input> in Polymer 2.x

I want to trigger an observer by entering text into a <paper-input> field.

When entering text into the zip code field, I expect to see the entered text logged to the console. Instead, I do not see anything in the console.

What am I doing wrong?

Here is the JSbin Demo.

http://jsbin.com/xahobojixe/1/edit?html,console,output
<!DOCTYPE html>
<html>

  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>JS Bin</title>

    <base href="//polygit.org/polymer+:master/components/">
    <script src="webcomponentsjs/webcomponents-lite.js"></script>
    <link rel="import" href="polymer/polymer-element.html">
    <link rel="import" href="paper-input/paper-input.html">

  </head>

  <body>

    <dom-module id="my-el">
      <template>
        <paper-input label="simple character counter" char-counter value="{{zipCode}}"></paper-input>
        [[zipCode]]
      </template>

      <script>
        class MyEl extends Polymer.Element {
          static get is() {
            return 'my-el';
          }

          static get properties() {
            /**/
            return {
              properties: {
                zipCode: {
                  type: String,
                  notify: true,
                  observer: '_zipCodeChanged',
                },
              },
            };
          }

          constructor() {
            super();
          }

          /**/
          ready() {
            super.ready();
          }

          _zipCodeChanged(s) {
            console.log('zip-code', s);
            console.log('zip-code-this', this.zipCode);
          }

        }

        window.customElements.define(MyEl.is, MyEl);

      </script>
    </dom-module>

    <my-el></my-el>
  </body>

</html>

Upvotes: 1

Views: 107

Answers (1)

tony19
tony19

Reputation: 138226

Your properties getter looks incorrect, as it contains a property named properties. The getter should be:

static get properties() {
  return {
    zipCode: {
      type: String,
      notify: true,
      observer: '_zipCodeChanged',
    },
  }
}

updated jsbin

Upvotes: 2

Related Questions