How to two-way bind iron-input to dom-repeat's item?
Asked Answered
P

1

6

I just started playing with Polymer 1.0 and am trying to do a very simple binding to collection. I am able to display text within dom-repeat, but the two-way binding to iron-input does not work. I tried array of strings, and objects. No luck.

<link rel="import" href="bower_components/polymer/polymer.html">
<link rel="import" href="bower_components/iron-input/iron-input.html">

<dom-module id="hello-world">
  <template>
    <ul>
      <template is="dom-repeat" items="{{data}}">
        <li>{{item.value}}</li>
      </template>
    </ul>

    <ul>
      <template is="dom-repeat" items="{{data}}">
        <li><input is="iron-input" bind-value="{{item.value}}"></input></li>
      </template>
    </ul>

  </template>
</dom-module>

<script>
  Polymer({
    is: "hello-world",

    ready: function() {
        this.data = [
          { value: "Hello"  },
          { value: "World!" }
        ];
    }
  });
</script>
Perfumery answered 10/6, 2015 at 6:30 Comment(0)
E
7

Change to: value="{{item.value::input}}" See here: http://plnkr.co/edit/QWdCk7ReXxtdKndwPdqq

Equisetum answered 10/6, 2015 at 15:0 Comment(2)
I remember looking at this last night, but somehow I didn't connect the dots. Thank you :-) P.S. Then what is the point of iron-input then? ;)Lahnda
Great fix! I went ahead and posted the issue in the polymer repo to see if the reason why the original code didn't work was a bug or a code problem: github.com/Polymer/polymer/issues/1821Underpinnings

© 2022 - 2024 — McMap. All rights reserved.