i’m new to extjs 4.
I have to use same from in different events
Creating a chapter and
Editing a created chapter
In both the situations all form fields are same
Is it better to use different forms for both the situations or can i use the same form instance in two places.
present i’m doing as follows
buttons: [{
text: 'Save',
handler: function () {
var cform = chapter_form.getForm();
cform.submit({
url: BASE_URL+'courses/chapters/saveChapter',
waitMsg:'Saving Data...',
success: function (res, req) {
cform.reset();
win2.destroy();
},
failure:function(form, action) {
}
});
}
},{
text: 'Update',
handler: function(){
var cuform = chapter_form.getForm();
cuform.submit({
url: BASE_URL+'courses/chapters/updateCourseChapter/'+chp_id,
waitMsg:'Saving Data...',
success: function (res, req) {
cuform.reset();
},
failure:function(form, action) {
}
});
}
}, {
text: 'Cancel',
handler: function () {
win2.destroy();
}
}]
Whats the better way to do?
I’d suggested use the same form for both actions. I usually do not separate update and create server actions. I have a general save action.
On server I check the posted model. If it has Id property set – it means that I should updated entity, otherwise I should create it. You could use ExtJs hidden form field to store the model id.