Nazariy
Nazariy

Reputation: 6088

How to serialize form inside modal window in ExtJS?

I'm trying to build modal windows on the fly from single javascript object passed by server. But I have no clue how can I serialize form inside modal window without defining form variable . In most examples serialize process look like this:

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

In my case all inner components like "form" are created from xtype value,and no variable is assigned to it. Is there any way to select and serialize form using something like this:

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

or what is apropriate way of doing so?

Upvotes: 2

Views: 5695

Answers (2)

stagl
stagl

Reputation: 521

I wrote a function to take values from a form and generate a string for adding 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 could be useful for someone?

Upvotes: 1

kwcto
kwcto

Reputation: 3504

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

To retrieve the form values of a FormPanel use myFormPanel.getForm().getValues()

That will come back with a js object representing the form fields.

Upvotes: 4

Related Questions