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
Allow NestedModel and Object editors' form options to be extended/ove…
…rridden.
  • Loading branch information
DouweM committed May 20, 2014
commit 6b2c3f072045f3d6adc9c6e75f0e862aa7fbe4af
14 changes: 8 additions & 6 deletions src/editors/nestedmodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ Form.editors.NestedModel = Form.editors.Object.extend({
Form.editors.Base.prototype.initialize.call(this, options);

if (!this.form) throw new Error('Missing required option "form"');
if (!options.schema.model) throw new Error('Missing required "schema.model" option for NestedModel editor');
if (!this.schema.model) throw new Error('Missing required "schema.model" option for NestedModel editor');
},

render: function() {
//Get the constructor for creating the nested form; i.e. the same constructor as used by the parent form
var NestedForm = this.form.constructor;
//Get the constructor for creating the nested form; by default the same constructor as used by the parent form
var NestedForm = this.schema.formClass || this.form.constructor;

var data = this.value || {},
key = this.key,
Expand All @@ -25,11 +25,13 @@ Form.editors.NestedModel = Form.editors.Object.extend({
//Wrap the data in a model if it isn't already a model instance
var modelInstance = (data.constructor === nestedModel) ? data : new nestedModel(data);

this.nestedForm = new NestedForm({
var formOptions = _.extend({
model: modelInstance,
idPrefix: this.id + '_',
fieldTemplate: 'nestedField'
});
Field: NestedForm.NestedField
}, _.result(this.schema, 'formOptions') || {});

this.nestedForm = new NestedForm(formOptions);

this._observeFormEvents();

Expand Down
9 changes: 5 additions & 4 deletions src/editors/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@ Form.editors.Object = Form.editors.Base.extend({

render: function() {
//Get the constructor for creating the nested form; i.e. the same constructor as used by the parent form
var NestedForm = this.form.constructor;
var NestedForm = this.schema.formClass || this.form.constructor;

//Create the nested form
this.nestedForm = new NestedForm({
var formOptions = _.extend({
schema: this.schema.subSchema,
data: this.value,
idPrefix: this.id + '_',
Field: NestedForm.NestedField
});
}, _.result(this.schema, 'formOptions') || {});

this.nestedForm = new NestedForm(formOptions);

this._observeFormEvents();

Expand Down