Skip to content

Commit

Permalink
Allow form elements to update non-owned model
Browse files Browse the repository at this point in the history
  • Loading branch information
pstjvn committed Jan 13, 2016
1 parent 187b2d0 commit 70fe85f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions element/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,18 @@ pstj.element.Form = goog.defineClass(pstj.material.Element, {
* Will try and map the form elements back to the data model.
* If there is a model set the changed values will be written on it and the
* CHNAGE event will fire on the model instance.
*
* @param {pstj.ds.DtoBase=} opt_model
* @protected
*/
updateModelFromElements: function() {
if (goog.isNull(this.getModel())) return;
var model = goog.asserts.assertInstanceof(this.getModel(),
updateModelFromElements: function(opt_model) {
var omodel = null;
if (goog.isDefAndNotNull(opt_model)) omodel = opt_model;
else if (!goog.isNull(this.getModel())) omodel = this.getModel();

if (goog.isNull(omodel)) return;

var model = goog.asserts.assertInstanceof(omodel,
pstj.ds.DtoBase).toJSON();
this.forEachChild(function(child) {
var name = child.name;
Expand All @@ -130,7 +137,7 @@ pstj.element.Form = goog.defineClass(pstj.material.Element, {
}
}
});
this.getModel().fromJSON(model);
omodel.fromJSON(model);
},

/**
Expand Down

0 comments on commit 70fe85f

Please sign in to comment.