Skip to content
Closed
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 @@ -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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check the element has actually changed ? && old != new ?

$(domReferencedElement).replaceWith(this.el);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this section seems unnecessary / not a common pattern in backbone-forms?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@philfreo I know... this is not a common pattern on this project, but also the List editor doesn't follow exactly the same pattern as the other editors.
Once you have inserted the form element into the DOM, a second call to listEditor.render() instead of updating the current element, will create a new one... this one new is not possible to trap or handle in any of the available events (there's no post-render trigger or something). So, this was the most viable solution I found =).


this.$el.attr('id', this.id);
this.$el.attr('name', this.key);

Expand Down Expand Up @@ -192,6 +201,7 @@
},

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