How to serialize a form inside a modal window in ExtJS?

I am trying to create modals on the fly from a single javascript object passed by the server. But I have no idea how I can serialize a form inside a modal without defining a form variable. In most examples, the serialization process looks like this:

//create form
var CustomForm = new Ext.FormPanel({...});
//submiting form
CustomForm.getForm().submit({...});

      

In my case, all internal components such as "form" are created from a value of type xtype and no variable is assigned to it. Is there a way to select and serialize the form using something like this:

Ext.get(this).select('form').serialize();

      

or what is the appropriate way to do this?

+2


source to share


2 answers


You can assign the form to an id and use Ext.getCmp (formid).

To get the values ​​of the FormPanel use myFormPanel.getForm().getValues()



This will return with a js object representing the form fields.

+4


source


I wrote a function to get values ​​from a form and create a string to add to the query string:

/**
 * takes an array of form values and converts them into a
 * query string
 * 
 * @param {object} Ext.form
 * @return {string} 
 */
this.serialize_form_values = function(form)
{
    var serial = '',
        values = form.getValues();

    for(var value in values)
        serial += '&' + value + '=' + values[value];

    return serial.substr(1);
};

      



Maybe it might be useful to someone?

+1


source







All Articles