Results 1 to 4 of 4

Thread: [solved]variables not posted on submit when form is in an object

  1. #1
    Ext JS Premium Member
    Join Date
    Aug 2007
    Location
    Germany
    Posts
    139

    Post [solved]variables not posted on submit when form is in an object

    I have shortend this code a lot but hope all necessary is still intact.
    Ok, here is my code in the mainfile:
    Code:
    	var object = new DTool.test();
    	object.preparePane('iform'); // apply to DIV iform
    	object.loadValues();  // LoadValues -> not needed for this example
    	object.submitValues(); // <--- here is the Problem ! Scope ?!
    If I dont put my form into this "DTool.test" construction submitting it is no problem.
    But if I submit it with the above function submitValues(); it only submits the values which have been set by the preparePane Function!

    Any changes outside these preparePane function are shown on screen and I can get them by
    Code:
    form.findField('titel').getValue();
    but they are not submitted. Always the initial data is submited.


    Code:
    DTool.test = function(){
        var test = new Ext.form.Form({ 
    	    waitMsg: 'Loading...',
    	    reader: new Ext.data.JsonReader({ 
    	         successProperty: 'success', 
    	         root: 'items'
    	    }, Ext.data.Record.create([
    	        { name: 'titel_name', mapping: 'titel', type: 'string' },
    	        { name: 'titel_id', mapping: 'id', type: 'int' }
    	    ]))
        });
    
        this.loadValues = function(){ 
        	test.load({
    		    url: 'getdata.php?r=int',
    		    waitMsg:'Loading...',
    			scope: 'DTool.test',
    			success: function(form, action) {
    			        form.findField('titel').setValue(action.result.data.titel_id);
    			    }			
    		});
    	};
    
        this.submitValues = function(){ 
    	test.submit({
    	method:'post',
    	scope: 'DTool.test',
            url: 'getdata.php?r=int',
            success: function(form, action){
              if (action.result.success == 'true')
              {
                // ...
              }
              else{
                //
              }        
            },								
            failure: function(form, action) {
              //
            }
          });
    	};
    		
        this.preparePane = function(pane){ 
    
    		var storeTitel = new Ext.data.Store({
    		    proxy: new Ext.data.HttpProxy({url: 'getdata.php?r=titel'}),
    		    reader: new Ext.data.JsonReader({
    		        totalProperty: 'results',
    		        root:'items'
    		    }, [{name: 'titel_id', mapping:'id'}, {name: 'titel_name' , mapping:'name'}])
    		}); 
    		storeTitel.load();
    	
    		titel = new Ext.form.ComboBox({
    	  		width:175,
    		    fieldLabel: "Titel",
    			name: 'titel',
    		    store: storeTitel,
    		    displayField:'titel_name',
    		    valueField: 'titel_id' ,
    		    typeAhead: true,
    		    mode: 'local',
    		    triggerAction: 'all',
    		    emptyText:'Titel',
    		    selectOnFocus:true
    		});
    		
    	
    		test.column({width:300, labelWidth:75, style:'margin-right:10px'});
      		test.fieldset(
    	        {legend:'test'},
    			titel
    	  	);
       		test.end();
                    test.render(pane);
        }
    };
    I think this should have something to do with scope or the this. identifier. I am relative new to javascript and i tried alot to get this work but without success.

    I made this construction to get the form definition out of my main js file. So i could apply the form to diffrent panes. May be there is a smarter way to archive my goal.

    Please help!
    Spirt

  2. #2
    Ext JS Premium Member
    Join Date
    Aug 2007
    Location
    Germany
    Posts
    139

    Thumbs up Solved my Problem

    Ok, after I had rewritten my code I got the thame failure, so I was wondering whats going on here. In the end it seems to me that it is a caching / timing problem.
    For testing I called loadValues(), and directly after that i called submitValues(). Maybe the application wasnt fully loaded or whatever. After i put an alert message between the 2 function calls it worked!
    Seems loadValues is a little bit slow(?!). Still a strange issue I think. But I have no Problem anymore with that...

  3. #3
    Sencha User mystix's Avatar
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    6,236

    Default

    both load and submit are asynchronous IIRC.

    i.e. the call to one is not dependent on the success of the other.

  4. #4
    Ext JS Premium Member
    Join Date
    Aug 2007
    Location
    Germany
    Posts
    139

    Default

    Your absolutly right, didnt thought about that.
    Thx

Posting Permissions

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