Skip to content

Commit

Permalink
bug(data binding): Workaround a Polymer bug
Browse files Browse the repository at this point in the history
Revert this once Polymer/polymer#3062
is fixed

[ci skip]
  • Loading branch information
ajtejankar committed Dec 10, 2015
1 parent 2db0f9f commit 370e155
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions t-data-feeder.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

<template is="dom-repeat" items={{data}} index-as={{index}}>
<div class="item">
<div class="text" contenteditable on-focus="moveCursorToEnd" tabindex="0" data-index="{{index}}">{{item}}</div>
<div class="text" contenteditable on-focus="moveCursorToEnd" tabindex="0" data-index="{{index}}">{{item.value}}</div>
<iron-icon icon="icons:cancel" tabindex="0" on-tap="deleteItem" data-index="{{index}}"></iron-icon>
</div>
</template>
Expand Down Expand Up @@ -136,12 +136,20 @@
var itemVal, newItemVal, item;

item = items[itemIdx];
itemVal = this.get('data.' + itemIdx);
/*
We need to wrap the values in an object because of
https://github.com/Polymer/polymer/issues/3062
*/
itemVal = this.get('data.' + itemIdx).value;

newItemVal = item.textContent;

if (newItemVal !== itemVal) {
this.set('data.' + itemIdx, newItemVal);
/*
We need to wrap the values in an object because of
https://github.com/Polymer/polymer/issues/3062
*/
this.set('data.' + itemIdx + '.value', newItemVal);
}

setTimeout(function() {
Expand Down Expand Up @@ -201,7 +209,11 @@
pushNewData: function(event, inputItem) {
setTimeout(function () {
/* add new item */
this.push('data', inputItem.textContent);
/*
We need to wrap the values in an object because of
https://github.com/Polymer/polymer/issues/3062
*/
this.push('data', {value: inputItem.textContent});
inputItem.textContent = '';

/* focus the new item */
Expand All @@ -227,7 +239,11 @@
if (itemIdx >= 0) {
items = this.getItems();
setTimeout(function () {
this.splice('data', itemIdx + 1, 0, '');
/*
We need to wrap the values in an object because of
https://github.com/Polymer/polymer/issues/3062
*/
this.splice('data', itemIdx + 1, 0, {value: ''});

setTimeout(function() {
var items = this.getItems();
Expand Down

0 comments on commit 370e155

Please sign in to comment.