Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List Editor setValue leak #526

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
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