Search code examples
extjsextjs4extjs4.1extjs4.2extjs5

ExtJs - Basic form: Is it possible to make params key a variable?


myFormPanel.getForm().submit({
    clientValidation: true,
    url: 'updateConsignment.php',
    params: {
        newStatus: 'delivered'
    },
    success: function(form, action) {
    },
        failure: function(form, action) {
        }
    }
});

In the code above, is it possible to set a variable as the parameter key? For example, if I had the following variable:

var myVar = 'newStatus';

and placed the variable as the param key, would the result be the same? or would it just take the variable as a string thus making the key 'myVar'?


Solution

  • You can do in the following way and assign it to params in the request:

    var formParams={};
    var myVar='newStatus';
    formParams[myVar]='delivered';
    console.log(formParams);

    myFormPanel.getForm().submit({
        clientValidation: true,
        url: 'updateConsignment.php',
        params: formParams,
        success: function(form, action) {
        },
            failure: function(form, action) {
            }
        }
    });