OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 @license |
| 3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. |
| 4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt |
| 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
| 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt |
| 7 Code distributed by Google as part of the polymer project is also |
| 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
| 9 --> |
| 10 |
| 11 <link rel="import" href="../polymer/polymer.html"> |
| 12 |
| 13 <!-- |
| 14 By default you can only get notified of changes to an `input`'s `value` due to u
ser input: |
| 15 |
| 16 <input value="{{myValue::input}}"> |
| 17 |
| 18 `iron-input` adds the `bind-value` property that mirrors the `value` property, a
nd can be used |
| 19 for two-way data binding. `bind-value` will notify if it is changed either by us
er input or by script. |
| 20 |
| 21 <input is="iron-input" bind-value="{{myValue}}"> |
| 22 |
| 23 --> |
| 24 <script> |
| 25 |
| 26 Polymer({ |
| 27 |
| 28 is: 'iron-input', |
| 29 |
| 30 extends: 'input', |
| 31 |
| 32 properties: { |
| 33 |
| 34 /** |
| 35 * Use this property instead of `value` for two-way data binding. |
| 36 */ |
| 37 bindValue: { |
| 38 observer: '_bindValueChanged', |
| 39 type: String |
| 40 } |
| 41 |
| 42 }, |
| 43 |
| 44 listeners: { |
| 45 'input': '_onInput' |
| 46 }, |
| 47 |
| 48 attached: function() { |
| 49 this.bindValue = this.value; |
| 50 }, |
| 51 |
| 52 _bindValueChanged: function() { |
| 53 this.value = this.bindValue; |
| 54 // manually notify because we don't want to notify until after setting val
ue |
| 55 this.fire('bind-value-changed', {value: this.bindValue}); |
| 56 }, |
| 57 |
| 58 _onInput: function(event) { |
| 59 this.bindValue = event.target.value; |
| 60 } |
| 61 |
| 62 }) |
| 63 </script> |
OLD | NEW |