Hybrid View

  1. #1
    Sencha User darthwes's Avatar
    Join Date
    Mar 2010
    Posts
    633
    Vote Rating
    -11
    darthwes can only hope to improve

      0  

    Cool BasicForm.reset: Resets to default values?

    BasicForm.reset: Resets to default values?


    If I have a form without any values / defaults declared and I .getForm().setValues() on it before I show the form, those values become defaults. Why?

    Here's a sample demo. If you click "Show the window" first, then the buttons work. If you click "Load some values" first, then the form never seems to reset no matter what button you click after that.

    Thanks.

    Code:
    Ext.onReady(function () {
    	var mWin = new Ext.Window({
    		title: "My Window",
    		width: 350,
    		padding: 10,
    		height: 200,
    		border: false,
    		modal: true,
    		resizable: false,
    		layout: 'fit',
    		closeAction: 'hide',
    		listeners: {
    			hide: function() {
    				this.items.get(0).getForm().reset();
    			}
    		},
    		items:[{
    			xtype: 'form',
    			labelWidth: 150,
    			defaults: {
    				width: 150
    			},
    			items:[{
    				xtype: 'textarea',
    				fieldLabel: 'Why?',
    				name: 'why'
    			}, {
    				xtype: 'numberfield',
    				fieldLabel: "How many?",
    				name: 'how'
    			}]
    		}]
    	});
    	
    	var bWin = new Ext.Window({
    		width: 250,
    		height: 150,
    		resizable: false,
    		layout: 'fit',
    		title: 'This is a test.',
    		items: [{
    			xtype: 'label',
    			text: 'This is only a test'
    		}],
    		buttons:[{
    			text: 'Show the window',
    			handler: function() {
    				mWin.show();
    			}
    		}, {
    			text: 'Load Some Values',
    			handler: function() {
    				var bForm = mWin.items.get(0).getForm();
    				bForm.setValues({
    					'why': 'I think',
    					'how': 42
    				});
    				mWin.show();
    			}
    		}]
    	});
    	
    	bWin.show();
    });
    Last edited by darthwes; 8 Oct 2010 at 5:57 PM. Reason: You need to start getting real specific...
    Wes

  2. #2
    Sencha User
    Join Date
    Aug 2009
    Posts
    480
    Vote Rating
    1
    plalx has a spectacular aura about plalx has a spectacular aura about

      0  

    Default


    The originalValue property on each fields is set at rendering time meaning that if you load values before the form gets loaded, those values becomes original values.

  3. #3
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    97
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    Correct. If you define all your fields with a 'value' that value will become the originalValue.

  4. #4
    Sencha User
    Join Date
    Sep 2010
    Posts
    55
    Vote Rating
    1
    alberto01 is on a distinguished road

      0  

    Default


    Hi,
    i have a similar problem.

    I have a form in which I load some datas.
    PHP Code:
    this.load(
    url: ... 

    ;

    If I call the reset() method, it clears all the data... but I would like to bring them to the last load.
    Is that possible?

    tnx al

  5. #5
    Sencha User
    Join Date
    Apr 2010
    Posts
    17
    Vote Rating
    0
    Akeru is on a distinguished road

      0  

    Default


    Hi,

    trackResetOnLoad should do it

  6. #6
    Sencha User
    Join Date
    Sep 2010
    Posts
    55
    Vote Rating
    1
    alberto01 is on a distinguished road

      0  

    Default


    Quote Originally Posted by Akeru View Post
    Hi,

    trackResetOnLoad should do it
    damn, it is exactly what I need !! Thanks.

    But it doesn't work .....

Similar Threads

  1. Ext.BasicForm.reset dumps original values for hidden fields
    By wwarby in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 24 Nov 2009, 12:21 PM
  2. [SOLVED] Radio not reset to their default values
    By senacle in forum Ext 2.x: Help & Discussion
    Replies: 4
    Last Post: 2 Jul 2009, 12:18 AM
  3. Replies: 2
    Last Post: 3 Oct 2008, 5:48 AM
  4. BasicForm.reset() does not clear fields?
    By dante in forum Ext 2.x: Help & Discussion
    Replies: 6
    Last Post: 30 May 2008, 4:14 AM
  5. Form fields reset to default on submitting
    By LorenzoW in forum Ext 1.x: Help & Discussion
    Replies: 2
    Last Post: 30 Apr 2007, 6:42 AM

Thread Participants: 4