Results 1 to 8 of 8

Thread: Clearing and Reusing a Form Panel?

  1. #1
    Ext JS Premium Member
    Join Date
    Jul 2010
    Posts
    17

    Default Clearing and Reusing a Form Panel?

    Ok, i have hacked my way around ExtJS in the past but google and the forum search function are just not aiding me with this. I'm sure the answer is obvious but i'm still at a loss. Any help or suggestions would be appreciated.

    I have a grid, when you select a row and click edit, a window pops up with a form panel, the record is loaded into the form panel, and when you click save, it updates the database record and reloads the datastore attached to the grid.

    The window object, as well as the form object are declared first and then used above.

    All is well.

    However, now i wanna use the same form panel to pop up when i click an add button to create a new record. However, when i click the add button and bring up the form panel, it is already filled out with the previous data that i edited before.

    Searches in the forum and google on how to clear a form didnt give me much, i found a function that you can use as a plugin that adds a "clear" function, but once i use that, all the fields come up red with failed validations.

    What is the best way to do this?

    Here is some snippets of my code:

    Code:
    var editaddpanel = new Ext.FormPanel({ 
            labelWidth:80,
            url:'update.php', 
        id: 'customer-form',
            frame:true, 
            title:'edit/add', 
            defaultType:'textfield',
        monitorValid:true,
    ....
    Just the beginning, and then i use the form in this window:

    Code:
    var win = new Ext.Window({
            layout:'fit',
            width:550,
            height:380,
            closable: false,
            resizable: false,
            plain: true,
            border: false,
            items: [editaddpanel]
        });
    So what is the best way to reuse a form panel object? or clear a form? or am i going about this wrong.

  2. #2
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    Call its reset() method?

  3. #3
    Ext JS Premium Member
    Join Date
    Jul 2010
    Posts
    17

    Default

    Quote Originally Posted by Animal View Post
    Call its reset() method?
    unfortunately, that just resets it back to when it was first loaded with data, it does not seem to clear it.

  4. #4

    Default

    I have same problem. I can only clear it by loading an empty record with form.loadRecord(). If there is better way to do this, please post it. Here is my solution:

    First, defined a record.
    Code:
    		var CustomerRecord=Ext.data.Record.create([
    		        {name:'customerUuid',type:'string'},
    		        {name:'id',type:'string'},
    		   	    {name:'name',type:'string'},
    		   		{name:'address',type:'string'},
    		   		{name:'zip',type:'string'},
    		   		{name:'tel',type:'string'},
    		   		{name:'cell',type:'string'},
    		   		{name:'paid',type:'int'},
    		   		{name:'bonus',type:'int'}
    	   		]);

    Clear the form by Form.loadRecord()
    Code:
    ...
    MyForm.getForm().loadRecord(new CustomerRecord({customerUuid:null,id:null,name:null,address:null,zip:null,tel:null,cell:null,paid:null,bonus:null}));

  5. #5

    Default

    I'm probably preaching the chore by now. Has anyone found the official solution for this? We have a widget where the requirements supports both Reset (resets to the old preloaded settings) and Clear (wiping out all the values within the form).

    Adding a dummy record to the form won't work in our workflow b/c it will erase the preloaded settings. That and it sounds like a hack...

    Thanks.

  6. #6
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    If you want to set all values to "", loop through the fields calling setValue

  7. #7

    Default

    Thanks, Animal. I had that as one of the solution. I guess I was looking to see if Ext supported such function within their API. I guess not... I wonder why...

  8. #8
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    They can't put in everything every person might want to do. The library would be the size of the universe.

Similar Threads

  1. Reusing form / variable fields
    By MatthewB in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 19 Aug 2008, 1:31 AM
  2. Reusing form elements in different tabs
    By Turban in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 22 May 2008, 3:13 PM
  3. Reusing panel definition
    By markfigley in forum Ext 2.x: Help & Discussion
    Replies: 4
    Last Post: 23 Jan 2008, 10:07 AM
  4. Clearing and reusing a BasicDialog
    By jthorn in forum Ext 1.x: Help & Discussion
    Replies: 0
    Last Post: 26 Sep 2007, 10:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •