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
43 changes: 26 additions & 17 deletions distribution.amd/backbone-forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -1963,7 +1963,7 @@ Form.editors.Object = Form.editors.Base.extend({

initialize: function(options) {
//Set default value for the instance so it's not a shared object
this.value = {};
this._setValue({});

//Init
Form.editors.Base.prototype.initialize.call(this, options);
Expand All @@ -1974,6 +1974,22 @@ Form.editors.Object = Form.editors.Base.extend({
},

render: function() {
this.$el.html(this.nestedForm.render().el);

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

return this;
},

getValue: function() {
if (this.nestedForm) return this.nestedForm.getValue();

return this.value;
},

_setValue: function(value) {
Form.editors.Base.prototype.setValue.call(this, value);

//Get the constructor for creating the nested form; i.e. the same constructor as used by the parent form
var NestedForm = this.form.constructor;

Expand All @@ -1986,23 +2002,10 @@ Form.editors.Object = Form.editors.Base.extend({
});

this._observeFormEvents();

this.$el.html(this.nestedForm.render().el);

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

return this;
},

getValue: function() {
if (this.nestedForm) return this.nestedForm.getValue();

return this.value;
},

setValue: function(value) {
this.value = value;

this._setValue(value);
this.render();
},

Expand Down Expand Up @@ -2057,13 +2060,17 @@ Form.editors.NestedModel = Form.editors.Object.extend({

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');

this._setValue(null);
},

render: function() {
_setValue: function(value) {
Form.editors.Base.prototype.setValue.call(this, value);

//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 data = this.value || {},
var data = value || {},
key = this.key,
nestedModel = this.schema.model;

Expand All @@ -2077,7 +2084,9 @@ Form.editors.NestedModel = Form.editors.Object.extend({
});

this._observeFormEvents();
},

render: function() {
//Render form
this.$el.html(this.nestedForm.render().el);

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

Large diffs are not rendered by default.

43 changes: 26 additions & 17 deletions distribution/backbone-forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -1974,7 +1974,7 @@ Form.editors.Object = Form.editors.Base.extend({

initialize: function(options) {
//Set default value for the instance so it's not a shared object
this.value = {};
this._setValue({});

//Init
Form.editors.Base.prototype.initialize.call(this, options);
Expand All @@ -1985,6 +1985,22 @@ Form.editors.Object = Form.editors.Base.extend({
},

render: function() {
this.$el.html(this.nestedForm.render().el);

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

return this;
},

getValue: function() {
if (this.nestedForm) return this.nestedForm.getValue();

return this.value;
},

_setValue: function(value) {
Form.editors.Base.prototype.setValue.call(this, value);

//Get the constructor for creating the nested form; i.e. the same constructor as used by the parent form
var NestedForm = this.form.constructor;

Expand All @@ -1997,23 +2013,10 @@ Form.editors.Object = Form.editors.Base.extend({
});

this._observeFormEvents();

this.$el.html(this.nestedForm.render().el);

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

return this;
},

getValue: function() {
if (this.nestedForm) return this.nestedForm.getValue();

return this.value;
},

setValue: function(value) {
this.value = value;

this._setValue(value);
this.render();
},

Expand Down Expand Up @@ -2068,13 +2071,17 @@ Form.editors.NestedModel = Form.editors.Object.extend({

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');

this._setValue(null);
},

render: function() {
_setValue: function(value) {
Form.editors.Base.prototype.setValue.call(this, value);

//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 data = this.value || {},
var data = value || {},
key = this.key,
nestedModel = this.schema.model;

Expand All @@ -2088,7 +2095,9 @@ Form.editors.NestedModel = Form.editors.Object.extend({
});

this._observeFormEvents();
},

render: function() {
//Render form
this.$el.html(this.nestedForm.render().el);

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

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions src/editors/nestedmodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ Form.editors.NestedModel = Form.editors.Object.extend({

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');

this._setValue(this.value);
},

render: function() {
_setValue: function(value) {
Form.editors.Base.prototype.setValue.call(this, value);

//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 data = this.value || {},
var data = value || {},
key = this.key,
nestedModel = this.schema.model;

Expand All @@ -32,7 +36,9 @@ Form.editors.NestedModel = Form.editors.Object.extend({
});

this._observeFormEvents();
},

render: function() {
//Render form
this.$el.html(this.nestedForm.render().el);

Expand Down
37 changes: 20 additions & 17 deletions src/editors/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,34 @@ Form.editors.Object = Form.editors.Base.extend({
hasNestedForm: true,

initialize: function(options) {
//Set default value for the instance so it's not a shared object
this.value = {};

//Init
Form.editors.Base.prototype.initialize.call(this, options);

//Set default value for the instance so it's not a shared object
this._setValue(this.value || {});

//Check required options
if (!this.form) throw new Error('Missing required option "form"');
if (!this.schema.subSchema) throw new Error("Missing required 'schema.subSchema' option for Object editor");
},

render: function() {
this.$el.html(this.nestedForm.render().el);

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

return this;
},

getValue: function() {
if (this.nestedForm) return this.nestedForm.getValue();

return this.value;
},

_setValue: function(value) {
Form.editors.Base.prototype.setValue.call(this, value);

//Get the constructor for creating the nested form; i.e. the same constructor as used by the parent form
var NestedForm = this.form.constructor;

Expand All @@ -37,23 +53,10 @@ Form.editors.Object = Form.editors.Base.extend({
});

this._observeFormEvents();

this.$el.html(this.nestedForm.render().el);

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

return this;
},

getValue: function() {
if (this.nestedForm) return this.nestedForm.getValue();

return this.value;
},

setValue: function(value) {
this.value = value;

this._setValue(value);
this.render();
},

Expand Down