You found a bug! We've classified it as TOUCH-1204 . We encourage you to continue the discussion and to find an acceptable workaround while we work on a permanent fix.
  1. #1
    Sencha User semiaddict's Avatar
    Join Date
    Mar 2010
    Posts
    45
    Vote Rating
    2
    semiaddict is on a distinguished road

      0  

    Default Alter form data using the beforesubmit event

    Alter form data using the beforesubmit event


    According to the documentation of the event beforesubmit in Ext.form.Panel , I should be able to modify the values submitted, but I can't figure out how.

    Implementations may adjust submitted form values or options prior to execution.
    I've tried modifying the variable values, but this has no effect.

    Any help is highly appreciated.

    Note: I'm basically trying to send a JSON string, so I need to encode the values using JSON.stringify.
    ---
    Oussama Mubarak // Semiaddict

  2. #2
    Sencha - Sencha Touch Dev Team rdougan's Avatar
    Join Date
    Oct 2008
    Posts
    1,158
    Vote Rating
    6
    rdougan will become famous soon enough

      0  

    Default


    This looks like a bug. Thanks for the report.
    Sencha Inc.
    Robert Dougan - @rdougan
    Sencha Touch 2 and Ext JS 4 Core Team Member, SASS/Theming Wizard.

  3. #3
    Sencha - Sencha Touch Dev Team rdougan's Avatar
    Join Date
    Oct 2008
    Posts
    1,158
    Vote Rating
    6
    rdougan will become famous soon enough

      0  

    Default


    This is working for me, using the following block of code:

    Code:
    var form = Ext.Viewport.add({
        xtype: 'formpanel',
        items: [
            {
                xtype: 'textfield',
                label: 'one',
                name: 'name',
                value: 'go'
            },
            {
                docked: 'bottom',
                xtype: 'toolbar',
                items: [
                    {
                        xtype: 'button',
                        text: 'submit',
                        handler: function() {
                            form.submit({
                                method: 'POST',
                                url: 'test'
                            });
                        }
                    }
                ]
            }
        ],
        listeners: {
            beforesubmit: function(form, values, options) {
                values.test = "hello";
            }
        }
    });
    This will post: 'name=go&test=hello'

    Sencha Inc.
    Robert Dougan - @rdougan
    Sencha Touch 2 and Ext JS 4 Core Team Member, SASS/Theming Wizard.

  4. #4
    Sencha User
    Join Date
    May 2007
    Location
    The Netherlands
    Posts
    187
    Vote Rating
    1
    mschering is on a distinguished road

      1  

    Default


    This does not seem to work in ST 2.3.1!
    Building Group-Office (http://www.group-office.com) with ExtJS: http://http://demo.group-office.eu user: demo / pass: demo

  5. #5
    Sencha User
    Join Date
    Mar 2013
    Location
    Caracas, Venezuela
    Posts
    3
    Vote Rating
    0
    beldar is on a distinguished road

      0  

    Default


    Any updates about this?

    I'm trying to add/change/format the values of the submit just like rdougan said, but is not working.

    Please help!



  6. #6
    Sencha User bruijn88's Avatar
    Join Date
    May 2008
    Posts
    66
    Vote Rating
    2
    bruijn88 is on a distinguished road

      0  

    Default


    I'm running into the same issue. The server expects a timestamp, but the form is sending something like:
    Tue Jan 01 1980 00:00:00 GMT+0100 (CET)

    I'm trying:
    PHP Code:
    onBeforeSubmit: function (formvaluesoptsevteOpts) {
        var 
    timestamp Ext.Date.format(values.dateOfBirth'U');
        
    values.dateOfBirth window.parseInt(timestamp10);

    to no avail. Using ST 2.3.1
    Is there a workaround/override?
    Last edited by bruijn88; 9 May 2014 at 11:33 PM. Reason: ST version

  7. #7
    Sencha User bruijn88's Avatar
    Join Date
    May 2008
    Posts
    66
    Vote Rating
    2
    bruijn88 is on a distinguished road

      0  

    Default


    I did some more digging and found the following.


    Ext.form.Panel#submit does:
    PHP Code:
    ...
    return 
    me.fireAction('beforesubmit', [meformValuesoptionse], 'doBeforeSubmit');
    ... 

    If you look at Ext.mixin.Observable#fireAction, it says:
    Fires the specified event with the passed parameters and execute a function (action) at the end if there are no listeners that return false.

    But if i step through the code using dev-tools, Ext.form.Panel#doBeforeSubmit (where the actual request is being done) is executed before my own event handler. This makes it quote obvious that the values cannot be altered before the request as documented by the Ext.form.Panel#beforesubmit event.

  8. #8
    Sencha User bruijn88's Avatar
    Join Date
    May 2008
    Posts
    66
    Vote Rating
    2
    bruijn88 is on a distinguished road

      0  

    Default


    Did some more digging and found a workaround.

    As stated above, Ext.form.Panel#doBeforeSubmit is executed before any listeners attached to the Ext.form.Panel#beforesubmit event. This is because the Ext.mixin.Observable#fireAction takes 2 more (undocumented) parameters, 'options' and 'order'. The last one indicates if the so called action, (Ext.form.Panel#doBeforeSubmit in this case) is executed before or after the registered listeners. The default seems to be before. To get around this i've overridden Ext.form.Panel#submit as follows:
    PHP Code:
    Ext.define('My.form.Panel', {
        
    override'Ext.form.Panel',

        
    submit: function(optionse) {
            var 
    me this,
            
    formValues me.getValues(me.getStandardSubmit() || !options.submitDisabled),
            
    form me.element.dom || {};

            if(
    this.getEnableSubmissionForm()) {
                
    form this.createSubmissionForm(formformValues);
            }

            
    options Ext.apply({
                
    url me.getUrl() || form.action,
                
    submitfalse,
                
    formform,
                
    method me.getMethod() || form.method || 'post',
                
    autoAbort false,
                
    params null,
                
    waitMsg null,
                
    headers null,
                
    success null,
                
    failure null
            
    }, options || {});

            
    // make sure 'doBeforeSubmit' is executed after any registered listeners
            
    return me.fireAction('beforesubmit', [meformValuesoptionse], 'doBeforeSubmit'me, {}, 'after');
        }
    }); 
    This fixes the order of execution problem, but we're not out of the woods yet.
    The 'values' parameter passed to the Ext.form.Panel#beforesubmit listener essentially gets tossed in Ext.form.Panel#doBeforeSubmit, so changing that in the listener is of no use. I figured i could instead set the value on the 'options.params' property, but unfortunately when the final querystring for the request is being assembled in Ext.data.Connection#setupParams, the serialized form (which still contains the old, non overridden value) is put after the params you just set, resulting in something like:
    valueToOverride=newValue&foo=bar&baz=qux&valueToOverride=oldValue
    and since the last one takes precedence, the old value is still the one you receive on the server end.

    To work around this problem you can just set the value of the form in the event listener like so:
    PHP Code:
    onBeforeSubmit: function (formvaluesoptionseeOpts) {
        
    // this has no effect
        
    values.valueToOverride 'newValue';

        
    // neither has this
        
    options.params = {
            
    valueToOverride'newValue'
        
    };

        
    // this does the trick
        
    Ext.fly(options.form).down('input[name=valueToOverride]'true).value 'newValue';

    Hope this helps anyone.

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi