PolymerElements / gold-phone-input

An input element that only allows phone numbers
https://webcomponents.org/element/PolymerElements/gold-phone-input
13 stars 30 forks source link

Formatting is not run when component nested in dom-repeat loop #66

Closed ermish closed 8 years ago

ermish commented 8 years ago

Description

Hey, Team!

When a gold-phone-input is nested in a dom-repeat, the formatting is not run on bound value. I believe I've tracked down the issue to this code:

_onValueChanged: function(value, oldValue) {
      // The initial property assignment is handled by `ready`.
      if (oldValue == undefined || value === oldValue)
        return;

It looks like if the element is not yet visible (since it's created in the dom-repeat loop), oldValue is undefined and the formatting is skipped. If oldValue == undefined is removed, it fixes the issue, but the function is ran sometimes unnecessarily.

I can create a pull request if this solution works.

Expected outcome

<template is="dom-repeat" items="{{model}}" as="item">
<gold-phone-input value="{{item.phone}}"> </gold-phone-input>
 </template>

should render 987-654-3210,

Actual outcome

Instead it renders 9876543210.

Live Demo

jsBin

Steps to reproduce

1.start with empty model (array)

  1. push a new item to model (I had the child as an object populated through ajax as well, not sure if this matters)
  2. voila!

    Browsers Affected

notwaldorf commented 8 years ago

Closing, as this doesn't have any reproducible steps (and from the described steps any number of things can go wrong). Please provide a JSBin with some repro code, and we'll reopen the issue then. Thanks!

ermish commented 8 years ago

I've added a demo. It looks like the issue also happens on initial data-binding in the jsBin.

RoXuS commented 7 years ago

+1

http://jsbin.com/sakegumovu/7/edit?html,console,output