Meredith
Meredith

Reputation: 4454

What else can I pass to the `form` property of Ext.Ajax.request?

Normally one posts an ExtJS form to the backend using form.submit({...}). I want to make my form submission synchronous now, so I'm switching to using Ext.Ajax.request({async: false, ...}). The form property of Ext.Ajax.request() usually looks like so:

Ext.Ajax.request({
    url: 'formsubmit',
    form: 'formid',
    method:'POST',
    success: function(response, opts) {
        alert("successfull");
    },
    failure:function(res,opt) {
        alert("request failed");
    }
});

I'm dealing with a bunch of anonymous forms right now. Is there any way around this?

Given a var form = {xtype: 'form', items: [...]} I've tried replacing 'formid' with form.getEl(), form.getForm(), and form.getForm().getFieldValues() which all don't work.

There's no other way around this other than assigning a generated id to each of my anonymous forms, is there.



Thanks for any input

Upvotes: 2

Views: 3637

Answers (2)

Chris Farmer
Chris Farmer

Reputation: 25396

It looks like you could just do this as an alternative to the form attribute:

var form = this.down('form');
Ext.Ajax.request({
    url: 'test.xyz',
    params: form.getValues()
    // etc...
});

getValues gives you the name/value pairs you need for your submission.

Upvotes: 2

Towler
Towler

Reputation: 1562

It looks like the ExtJS forms do not actually use form elements in the markup. When the submit function is called on an ExtJS form, an HTML form element is crafted as part of the process, and that's the form that is used for the submission.

http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.form.action.Submit-method-buildForm

Ideally, you could modify the options that are used in the Ajax request called within the doSubmit function. Since you can't, you might want to consider overriding Ext.form.action.Submit such that you can, then calling the form.submit() function you mentioned in your question.

http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.form.action.Submit-method-doSubmit

Upvotes: 1

Related Questions