PDA

View Full Version : Reset a re-used FormPanel



SimonSays
16 Jul 2011, 3:49 PM
hi

i understand that the reset() method of the FormPanel resets all fields to their INITIAL values. this does not work as expected if a form gets re-used.

here's the scenario:
- create a new form
- load model A into the form
- load model B into the form
- reset the form -> form gets reverted to the values of model A

is there a way to reset the form to the values of the last loaded model?

thx
Simon

dawesi
17 Jul 2011, 1:51 PM
why not destroy the form panel after use and then recreate it. this would reduce memory footprint also.

SimonSays
19 Jul 2011, 12:15 PM
i thought about this possibility too, but decided against it because this form is a base component of my app and is used very frequently, so a new instance had to be created all the time.

i implemented now my own reset() functionality.


var currentEditorModelClone;
function createModelClone(){
var editor = myapp.views.MyEditor;
var rec = editor.getRecord();
currentEditorModelClone = rec.copy();
}

function revertModel(model){
for(prop in currentEditorModelClone.data){
model.data[prop] = currentEditorModelClone.data[prop];
}
}