1. #1
    Ext User
    Join Date
    Jun 2008
    Posts
    32
    Vote Rating
    0
    scottpenrose is on a distinguished road

      0  

    Default Ext.Direct form submit without formHandler

    Ext.Direct form submit without formHandler


    Hey Team,

    I would like to do an Ext.Direct form Post without "formHandler" set. I.e. I want the form to post JSON.
    Code:
                api: {
                    load: MyAPI.get,
                    submit: MyAPI.set
                },
                baseParams: {id: this.customerId},
                paramsAsHash: true,
    The get works perfectly. The set however, sends the following:

    Code:
        that.getForm().submit();
    via firebug I see that posted is:

    Code:
    {"action":"MyAPI","method":"set","data":[{"occupant":{"qtip":""},"other":{"qtip":""}}],"type":"rpc","tid":5}
    I can just do a form serialise and send the data. But I imagine there is an easier inbuilt way?

    Scott

  2. #2
    Ext User
    Join Date
    Jun 2008
    Posts
    32
    Vote Rating
    0
    scottpenrose is on a distinguished road

      0  

    Default


    Why do we ever need to set "formHandler" ? It appears that a form can only post data to Ext.Direct that is setup as a formHandler, and it appears that other request must not be a formHandler or they don't work at all (or at least do not fire when called).

    Here is a simple example:
    Code:
    Ext.onReady(function(){
    	Ext.Direct.addProvider({
    		url: "/direct/cgi/simple/router.cgi",
    		type:"remoting",
    		actions: {
    			Profile: [
    				{
    					name: 'doTest',
    					len: 1,
    					formHandler: false
    				}
    			]
    		}
    	});
        	console.log("Calling doTest");
    	Profile.doTest('Scott', function(result, e) {
    		console.log("Returned result", result);
    	});
    });
    If you set formHandler: true - you do not get a request on the server, nor (obviously) a reply. If you set it to 'false' it all works as expected.

    Now take the opposite, and use it in a form:
    Code:
       api: {
           load: Profile.getBasicInfo,
           submit: Profile.updateBasicInfo
       },
    then if you set formHandler: true in the api you get the correct form data posted as expected, but if you set it to false you get:
    Code:
    "data":[{"occupant":{"qtip":""},"other":{"qtip":""}}]
    So there is one of two possibilities I can see.
    1. I am not setting it up correctly to allow JSON instead of form data to be sent on a form.
    2. OR it is unnecessary to setup the formHandler ever because it is implied and internally understood anyway.

    Scott

  3. #3
    Ext User
    Join Date
    Oct 2008
    Location
    Poland
    Posts
    1
    Vote Rating
    0
    tefnet is on a distinguished road

      0  

    Default


    We end up doing something like that... (more or less... not sure if it will work because I had to cut/paste part of our class)

    Code:
    Ext.form.Action.TefDirectSubmit = Ext.extend(Ext.form.Action.DirectSubmit, {
        run : function(){
            var o = this.options;
            if(o.clientValidation === false || this.form.isValid()){
                // tag on any additional params to be posted in the
                // form scope
                this.success.params = this.getParams();
                this.form.api.submit(this.form.getValues(), this.success, this);
            }else if (o.clientValidation !== false){ // client validation failed
                this.failureType = Ext.form.Action.CLIENT_INVALID;
                this.form.afterAction(this, false);
            }
        }
    }
    Ext.form.Action.ACTION_TYPES['directsubmit'] = Ext.form.Action.TefDirectSubmit;
    The idea is to send this.form.getValues(), not this.form.el.dom

Thread Participants: 1