From 9cc58a0f7a6f2e3fd2a8159c0bcf341ef96fede1 Mon Sep 17 00:00:00 2001 From: lordfuoco Date: Wed, 26 Oct 2016 16:38:56 +0200 Subject: [PATCH 1/3] switched children adding to event based system --- etools-repeatable-field-set.html | 47 +++++++++++++++++--------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/etools-repeatable-field-set.html b/etools-repeatable-field-set.html index d6aaff3..eda511f 100644 --- a/etools-repeatable-field-set.html +++ b/etools-repeatable-field-set.html @@ -256,6 +256,14 @@ deleteConfirmationMessage: { type: String, value: 'Are you sure you want to delete this item?' + }, + _itemCounter: { + type: Number, + value: 0 + }, + _isCopy: { + type: Number, + value: -1 } }, _getHasCounterClass: function(showCounter) { @@ -283,11 +291,6 @@ if (!this.hidePlus) { var newObj = this._getItemModelObject(); this.push('model', newObj); - this.async(function() { - var children = this._getPureChildren(); - var index = children.length - 1; - this.$$('#item-' + index).appendChild(children[index]); - }); } }, _openDeleteConfirmation: function(event) { @@ -303,6 +306,7 @@ container.removeChild(firstChild); firstChild = container.firstChild; } + this._itemCounter -= 1; this.splice('model', index, 1); } } @@ -311,11 +315,8 @@ if (!this.hidePlus && this.allowCopy) { var index = parseInt(Polymer.dom(event).localTarget.getAttribute('data-args'), 10); var copy = JSON.parse(JSON.stringify(this.model[index])); + this._isCopy = index + 1; this.splice('model', index + 1, 0, copy); - this.async(function() { - var children = this._getPureChildren(); - this.$$('#item-' + (index + 1)).appendChild(children[index + 1]); - }); } }, _toggle: function() { @@ -353,20 +354,16 @@ Polymer.dom(this.deleteDialog.root).querySelector('paper-dialog-scrollable').appendChild(deleteConfirmationContent); }, - _printLightDom: function() { + _printLightDom: function(children) { var self = this; - self.async(function() { - var children = self._getPureChildren(); - children.forEach(function(child, index) { - self.$$('#item-' + index).appendChild(child); + if(this._isCopy !== -1 ) { + this._itemCounter = this._isCopy; + this._isCopy = -1; + } + children.forEach(function(child) { + self.$$('#item-' + self._itemCounter).appendChild(child); + self._itemCounter += 1; }); - }); - }, - - _getPureChildren: function() { - return this.getEffectiveChildren().filter(function(item){ - return item.localName !== 'template'; - }); }, ready: function() { if (!this.hidePlus) { @@ -374,7 +371,13 @@ } }, attached: function() { - this._printLightDom(); + Polymer.dom(this).observeNodes(function(info) { + var addedChildren = info.addedNodes.filter(function(item) { + return item.localName !== 'template' && item.nodeName !== '#text'; + }); + this._printLightDom(addedChildren) + }); + }, detached: function() { if (!this.hidePlus) { From 0deb59dc7e84833c0688f0ec1194f8c758a430a3 Mon Sep 17 00:00:00 2001 From: lordfuoco Date: Wed, 26 Oct 2016 17:37:30 +0200 Subject: [PATCH 2/3] added more flex classes to style --- etools-repeatable-field-set.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etools-repeatable-field-set.html b/etools-repeatable-field-set.html index eda511f..efea1f4 100644 --- a/etools-repeatable-field-set.html +++ b/etools-repeatable-field-set.html @@ -45,7 +45,7 @@