Skip to content

Commit

Permalink
Merge branch 'fix-userinitiated' of https://github.com/elasticsales/b…
Browse files Browse the repository at this point in the history
…ackbone-forms

Add addItem docs
  • Loading branch information
powmedia committed Aug 15, 2012
1 parent c6d56d4 commit 461c3c7
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 22 deletions.
4 changes: 3 additions & 1 deletion distribution.amd/backbone-forms.js
Expand Up @@ -332,7 +332,9 @@ var Form = (function() {
*/ */
setValue: function(data) { setValue: function(data) {
for (var key in data) { for (var key in data) {
this.fields[key].setValue(data[key]); if (_.has(this.fields, key)) {
this.fields[key].setValue(data[key]);
}
} }
}, },


Expand Down
2 changes: 1 addition & 1 deletion distribution.amd/backbone-forms.min.js

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions distribution.amd/editors/list.js
Expand Up @@ -19,7 +19,7 @@ define(['jquery', 'underscore', 'backbone'], function($, _, Backbone) {
events: { events: {
'click [data-action="add"]': function(event) { 'click [data-action="add"]': function(event) {
event.preventDefault(); event.preventDefault();
this.addItem(); this.addItem(null, true);
} }
}, },


Expand All @@ -31,7 +31,8 @@ define(['jquery', 'underscore', 'backbone'], function($, _, Backbone) {


//List schema defaults //List schema defaults
this.schema = _.extend({ this.schema = _.extend({
listTemplate: 'list' listTemplate: 'list',
listItemTemplate: 'listItem'
}, schema); }, schema);


//Determine the editor to use //Determine the editor to use
Expand Down Expand Up @@ -86,7 +87,8 @@ define(['jquery', 'underscore', 'backbone'], function($, _, Backbone) {


/** /**
* Add a new item to the list * Add a new item to the list
* @param {Mixed} [value] Value for the new item editor * @param {Mixed} [value] Value for the new item editor
* @param {Boolean} [userInitiated] If the item was added by the user clicking 'add'
*/ */
addItem: function(value, userInitiated) { addItem: function(value, userInitiated) {
var self = this; var self = this;
Expand All @@ -113,7 +115,7 @@ define(['jquery', 'underscore', 'backbone'], function($, _, Backbone) {
args.splice(1, 0, self); args.splice(1, 0, self);
// args = ["item:key:change", this=listEditor, itemEditor, fieldEditor] // args = ["item:key:change", this=listEditor, itemEditor, fieldEditor]


editors.List.prototype.trigger.apply(this, args) editors.List.prototype.trigger.apply(this, args);
}, self); }, self);


item.editor.on('change', function() { item.editor.on('change', function() {
Expand Down Expand Up @@ -146,7 +148,7 @@ define(['jquery', 'underscore', 'backbone'], function($, _, Backbone) {
self.trigger('add', self, item.editor); self.trigger('add', self, item.editor);
self.trigger('change', self); self.trigger('change', self);
} }
} };


//Check if we need to wait for the item to complete before adding to the list //Check if we need to wait for the item to complete before adding to the list
if (this.Editor.isAsync) { if (this.Editor.isAsync) {
Expand Down Expand Up @@ -291,7 +293,7 @@ define(['jquery', 'underscore', 'backbone'], function($, _, Backbone) {
}).render(); }).render();


//Create main element //Create main element
var $el = $(Form.templates.listItem({ var $el = $(Form.templates[this.schema.listItemTemplate]({
editor: '<b class="bbf-tmp"></b>' editor: '<b class="bbf-tmp"></b>'
})); }));


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.

4 changes: 3 additions & 1 deletion distribution/backbone-forms.js
Expand Up @@ -345,7 +345,9 @@ var Form = (function() {
*/ */
setValue: function(data) { setValue: function(data) {
for (var key in data) { for (var key in data) {
this.fields[key].setValue(data[key]); if (_.has(this.fields, key)) {
this.fields[key].setValue(data[key]);
}
} }
}, },


Expand Down
2 changes: 1 addition & 1 deletion distribution/backbone-forms.min.js

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions distribution/editors/list.js
Expand Up @@ -17,7 +17,7 @@
events: { events: {
'click [data-action="add"]': function(event) { 'click [data-action="add"]': function(event) {
event.preventDefault(); event.preventDefault();
this.addItem(); this.addItem(null, true);
} }
}, },


Expand All @@ -29,7 +29,8 @@


//List schema defaults //List schema defaults
this.schema = _.extend({ this.schema = _.extend({
listTemplate: 'list' listTemplate: 'list',
listItemTemplate: 'listItem'
}, schema); }, schema);


//Determine the editor to use //Determine the editor to use
Expand Down Expand Up @@ -84,7 +85,8 @@


/** /**
* Add a new item to the list * Add a new item to the list
* @param {Mixed} [value] Value for the new item editor * @param {Mixed} [value] Value for the new item editor
* @param {Boolean} [userInitiated] If the item was added by the user clicking 'add'
*/ */
addItem: function(value, userInitiated) { addItem: function(value, userInitiated) {
var self = this; var self = this;
Expand All @@ -111,7 +113,7 @@
args.splice(1, 0, self); args.splice(1, 0, self);
// args = ["item:key:change", this=listEditor, itemEditor, fieldEditor] // args = ["item:key:change", this=listEditor, itemEditor, fieldEditor]


editors.List.prototype.trigger.apply(this, args) editors.List.prototype.trigger.apply(this, args);
}, self); }, self);


item.editor.on('change', function() { item.editor.on('change', function() {
Expand Down Expand Up @@ -144,7 +146,7 @@
self.trigger('add', self, item.editor); self.trigger('add', self, item.editor);
self.trigger('change', self); self.trigger('change', self);
} }
} };


//Check if we need to wait for the item to complete before adding to the list //Check if we need to wait for the item to complete before adding to the list
if (this.Editor.isAsync) { if (this.Editor.isAsync) {
Expand Down Expand Up @@ -289,7 +291,7 @@
}).render(); }).render();


//Create main element //Create main element
var $el = $(Form.templates.listItem({ var $el = $(Form.templates[this.schema.listItemTemplate]({
editor: '<b class="bbf-tmp"></b>' editor: '<b class="bbf-tmp"></b>'
})); }));


Expand Down

0 comments on commit 461c3c7

Please sign in to comment.