Skip to content

Commit

Permalink
Create separate List#renderItems for use in setValue since render her…
Browse files Browse the repository at this point in the history
…e was creating an orphaned el (Resolves powmedia#282)
  • Loading branch information
bpardee committed Dec 19, 2013
1 parent 169def7 commit c1e61f8
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 38 deletions.
32 changes: 20 additions & 12 deletions distribution.amd/editors/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,31 @@ define(['jquery', 'underscore', 'backbone', 'backbone-forms'], function($, _, Ba
},

render: function() {
var self = this,
value = this.value || [];

//Create main element
var $el = $($.trim(this.template()));

//Store a reference to the list (item container)
this.$list = $el.is('[data-items]') ? $el : $el.find('[data-items]');

this.renderItems();

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

if (this.hasFocus) this.trigger('blur', this);

return this;
},

renderItems: function() {
var self = this,
value = this.value || [];

// Remove any old items
this.items = [];
this.$list.empty();

//Add existing items
if (value.length) {
_.each(value, function(itemValue) {
Expand All @@ -70,14 +86,6 @@ define(['jquery', 'underscore', 'backbone', 'backbone-forms'], function($, _, Ba
else {
if (!this.Editor.isAsync) this.addItem();
}

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

if (this.hasFocus) this.trigger('blur', this);

return this;
},

/**
Expand Down Expand Up @@ -194,7 +202,7 @@ define(['jquery', 'underscore', 'backbone', 'backbone-forms'], function($, _, Ba

setValue: function(value) {
this.value = value;
this.render();
this.renderItems();
},

focus: function() {
Expand Down
2 changes: 1 addition & 1 deletion distribution.amd/editors/list.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 20 additions & 12 deletions distribution/editors/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,31 @@
},

render: function() {
var self = this,
value = this.value || [];

//Create main element
var $el = $($.trim(this.template()));

//Store a reference to the list (item container)
this.$list = $el.is('[data-items]') ? $el : $el.find('[data-items]');

this.renderItems();

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

if (this.hasFocus) this.trigger('blur', this);

return this;
},

renderItems: function() {
var self = this,
value = this.value || [];

// Remove any old items
this.items = [];
this.$list.empty();

//Add existing items
if (value.length) {
_.each(value, function(itemValue) {
Expand All @@ -68,14 +84,6 @@
else {
if (!this.Editor.isAsync) this.addItem();
}

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

if (this.hasFocus) this.trigger('blur', this);

return this;
},

/**
Expand Down Expand Up @@ -192,7 +200,7 @@

setValue: function(value) {
this.value = value;
this.render();
this.renderItems();
},

focus: function() {
Expand Down
Loading

0 comments on commit c1e61f8

Please sign in to comment.