Search code examples
polymer

Polymer element blur event


I am trying to see what is easy to do with polymer and am having a hard time getting the seemingly simplest events to fire.

<polymer-element name="field" attributes=" type name value">
  <template>
    <label>{{name}}
      <input  type={{type}} name={{name}} value={{value}}>
    </label>
  </template>
  <script>
    Polymer('field', {
      onblur: function () {
        console.log('blurred');
      }
    })
  </script>
</polymer-element>

I have created this element and want to do something on blur does anyone know what I am missing or where in the docs I should be looking?


Solution

    1. name="field" doesn't match Polymer('profile-field', but I assume that's just some kind of typo.

    2. blur events do not bubble, so your input blurring is not going to result in a blur event on your host element.

    3. it's best not to override on<event> functions, you are better off using Polymer event binding.

    I'm not sure if this is actually what you are after, but here is an example that listens to blur on the input itself.

    <polymer-element name="profile-field" attributes="type name value">
      <template>
        <label>{{name}}
          <input on-blur="{{inputBlur}}" type="{{type}}" name="{{name}}" value="{{value}}">
        </label>
      </template>
      <script>
        Polymer('profile-field', {
          inputBlur: function () {
            console.log('input blurred');
          }
        })
      </script>
    </polymer-element>