From ba25f15caa46628a27d58887045d01736d16cea7 Mon Sep 17 00:00:00 2001 From: Gerardo Bort Date: Wed, 2 Apr 2014 15:53:48 -0300 Subject: [PATCH 1/2] bugfix: editors.List:setValue() wrong behavior: it was accumulating elements on each call, apart of that, the render() method wasnt refreshing the DOM after the first call (called after by setValue) --- src/editors/extra/list.js | 10 ++++++++++ test/editors/extra/list.js | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/editors/extra/list.js b/src/editors/extra/list.js index 15805dde..03f77b09 100644 --- a/src/editors/extra/list.js +++ b/src/editors/extra/list.js @@ -70,7 +70,16 @@ if (!this.Editor.isAsync) this.addItem(); } + //Save a copy of the pre-exising element, if exists + var domReferencedElement = this.el; + this.setElement($el); + + //In case of there was a pre-existing element already placed in the DOM, then update it + if (domReferencedElement) { + $(domReferencedElement).replaceWith(this.el); + } + this.$el.attr('id', this.id); this.$el.attr('name', this.key); @@ -192,6 +201,7 @@ }, setValue: function(value) { + this.items = []; this.value = value; this.render(); }, diff --git a/test/editors/extra/list.js b/test/editors/extra/list.js index 77fcc3f6..56e3d8e2 100644 --- a/test/editors/extra/list.js +++ b/test/editors/extra/list.js @@ -87,6 +87,16 @@ var same = deepEqual; same(list.getValue(), ['a', 'b', 'c']); }); + test('setValue() - updates input value - more than once', function() { + var list = new List().render(); + + list.setValue(['a', 'b', 'c']); + same(list.getValue(), ['a', 'b', 'c']); + + list.setValue(['d', 'e', 'f']); + same(list.getValue(), ['d', 'e', 'f']); + }); + test('validate() - returns validation errors', function() { var list = new List({ schema: { validators: ['required', 'email'] }, From 2fa4214e5ae0a4af98eaf542158b7b33f7418508 Mon Sep 17 00:00:00 2001 From: Glen Pike Date: Mon, 3 Oct 2016 16:17:23 +0100 Subject: [PATCH 2/2] gerardobort-master: Add test for Add button after List.setValue In fiddle https://jsfiddle.net/sniederb/zkmtnkux/8/ The Add button didn't work after you clicked the "Run setValues" button. --- test/editors/extra/list.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/editors/extra/list.js b/test/editors/extra/list.js index 3a4822b4..7e5fdab6 100644 --- a/test/editors/extra/list.js +++ b/test/editors/extra/list.js @@ -178,6 +178,16 @@ var same = deepEqual; same(list.getValue(), ['d', 'e', 'f']); }); + test('setValue() - add button works after calling setValue', function() { + var list = new List().render(); + + list.setValue(['a', 'b', 'c']); + + list.$('[data-action="add"]').click(); + + same(list.items.length, 4); + }); + test('validate() - returns validation errors', function() { var list = new List({ schema: { validators: ['required', 'email'] },