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
3 changes: 2 additions & 1 deletion distribution.amd/backbone-forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ var Form = Backbone.View.extend({
$ = Backbone.$;

//Render form
var $form = $($.trim(this.template(_.result(this, 'templateData'))));
var templateData = _.extend(this.model ? this.model.attributes : {}, _.result(this, 'templateData'));
var $form = $($.trim(this.template(templateData)));

//Render standalone editors
$form.find('[data-editors]').add($form).each(function(i, el) {
Expand Down
2 changes: 1 addition & 1 deletion distribution.amd/backbone-forms.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion distribution/backbone-forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ var Form = Backbone.View.extend({
$ = Backbone.$;

//Render form
var $form = $($.trim(this.template(_.result(this, 'templateData'))));
var templateData = _.extend(this.model ? this.model.attributes : {}, _.result(this, 'templateData'));
var $form = $($.trim(this.template(templateData)));

//Render standalone editors
$form.find('[data-editors]').add($form).each(function(i, el) {
Expand Down
2 changes: 1 addition & 1 deletion distribution/backbone-forms.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ var Form = Backbone.View.extend({
$ = Backbone.$;

//Render form
var $form = $($.trim(this.template(_.result(this, 'templateData'))));
var templateData = _.extend(this.model ? this.model.attributes : {}, _.result(this, 'templateData'));
var $form = $($.trim(this.template(templateData)));

//Render standalone editors
$form.find('[data-editors]').add($form).each(function(i, el) {
Expand Down
17 changes: 16 additions & 1 deletion test/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,28 @@ test('uses from model if provided - when schema is a function', function() {
same(form.schema, model.schema());
});

test('Model attributes are accessible on template', function() {
var model = new Backbone.Model({
'fromModel': 'model'
});

var options = {
model: model,
templateData: {'fromOptions': 'options'},
template: _.template('<p><%= fromModel %>, <%= fromOptions %></p>')
};

var form = new Form(options).render();
same(form.$el.html(), 'model, options');
});

test('stores important options', function() {
var options = {
model: new Backbone.Model(),
data: { foo: 1 },
idPrefix: 'foo',
templateData: { bar: 2 }
}
};

var form = new Form(options);

Expand Down