Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/editors/extra/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,16 @@

this._checkMaxCardinalityReached($el);

//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);

Expand Down Expand Up @@ -224,6 +233,7 @@
},

setValue: function(value) {
this.items = [];
this.value = value;
this.render();
},
Expand Down
20 changes: 20 additions & 0 deletions test/editors/extra/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,26 @@ 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('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'] },
Expand Down