From 11c9739d362a80657a0c0a429d0e6b4e8e27f2e3 Mon Sep 17 00:00:00 2001 From: Renaud Le Gac <renaud.legac@free.fr> Date: Sun, 13 Mar 2011 14:44:45 +0000 Subject: [PATCH] Add the hardReset method. --- static/plugin_dbui/src/appform.js | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/static/plugin_dbui/src/appform.js b/static/plugin_dbui/src/appform.js index 335082e3..8b8975b7 100644 --- a/static/plugin_dbui/src/appform.js +++ b/static/plugin_dbui/src/appform.js @@ -158,6 +158,22 @@ App.form.FormPanel = Ext.extend(Ext.form.FormPanel, { } }, + /** + * Private method to hardreset the form + * The reset method resets the field value to the originally loaded. + * The hardreset erases the originally loaded values and reset the form. + * Hardreset is required to clean form in sequence like update, create,... + */ + hardReset: function () { + var form = this.getForm(); + + form.items.each(function (field) { + field.originalValue = ""; + }); + + form.reset(); + }, + /** * Private handler to process store exception * the scope of this function is App.form.FormPanel @@ -199,7 +215,9 @@ App.form.FormPanel = Ext.extend(Ext.form.FormPanel, { */ setAction: function (action, record) { - var form = this.getForm(); + var form = this.getForm(), + table, + tableId; this.buttonReset.show(); this.buttonAction.show(); @@ -209,11 +227,13 @@ App.form.FormPanel = Ext.extend(Ext.form.FormPanel, { this.currentAction = action; this.currentRecord = record; + this.hardReset(); + switch (action) { case 'create': + this.buttonAction.setText(this.textCreate); - form.reset(); break; case 'destroy': @@ -223,8 +243,9 @@ App.form.FormPanel = Ext.extend(Ext.form.FormPanel, { case 'duplicate': this.buttonAction.setText(this.textDuplicate); - form.reset(); - delete record.id; + table = App.getTableName(this.store); + tableId = App.encodeField(table, 'id'); + delete record.data[tableId]; form.loadRecord(record); break; -- GitLab