PDA

View Full Version : ext3 -> ext4 = myform.getForm().getEl is not a function



nik600
4 Feb 2012, 11:16 AM
Dear alli'm trying to send the fields of a Ext.form.Panel into an AJAX request.This is the code of my form:



var myform = new Ext.FormPanel({
frame:true,
autoScroll:true,
closable :true,
title: 'My Form Title',
defaultType: 'label',
items: [{
text: 'Type your name',
xtype:'textfield' }]
});


and this is the piece of javascript that i call when i want to send the form data to server:




Ext.Ajax.request({
url : 'Save.php',
method : 'POST',
form : myform.getForm().getEl().dom,
success : function(result, request) {alert('ok');},
failure : function(result, request) {alert('ok');}
});


The problem is that the getEl() method seems to be unavailable and i get this error:


myform.getForm().getEl is not a function

This code was working with extjs 3.x, and is not working with 4.x, can you help me to understand where is the problem?

Thanks

Farish
5 Feb 2012, 1:49 AM
I havent looked into your code completely but one error could be that in form, just use myform.getForm(). Take a look at this example and you should be able to find any differences between your version and ExtJS 4.

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.Basic

nik600
5 Feb 2012, 6:29 AM
Thanks for your reply but if i use:



Ext.Ajax.request({
url : 'Save.php',
method : 'POST',
form : myform.getForm(),
success : function(result, request) {alert('ok');},
failure : function(result, request) {alert('ok');}
});


i get a different error:



form.getAttribute is not a function

Farish
5 Feb 2012, 6:51 AM
why dont you try the submit method of the Basic Form:

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.Basic-method-submit

nik600
5 Feb 2012, 7:15 AM
Because i have some code that handles some custom controls on all my forms and then submit it using an Ext.Ajax.request request.

i've seen that the Ext.Ajax.request method still support the form parameter, so i need to understand how to use it and where is the difference between the ext3 and ext4.

If i have no chances to reuse it, i'll change my code.

Thanks

nik600
5 Feb 2012, 9:38 AM
another problem is that not all my requests gives JSON response as the submit of the form creates a file-download on server-side.

in some situation i change the target of the form to open a _BLANK page.

Basically, i need to access to the getEl() method and then getEl().dom object, is it possible using extjs4 ?

Thanks

Farish
5 Feb 2012, 9:43 AM
There is a getEl() member for the Form:

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.Panel-method-getEl

however, the comment there points out that it will only return a valid element if the component is rendered. may be that is what was causing the error...

nik600
5 Feb 2012, 9:57 AM
Yes but it returns the html div that contains the FormPanel, i need the dom form element.

Farish
5 Feb 2012, 10:00 AM
try the getDom() method:

http://docs.sencha.com/ext-js/4-0/#!/api/Ext-method-getDom

hendricd
5 Feb 2012, 12:41 PM
@nik600 --

Ext 4 does not render a <form> element any more. ;) (So that unrendered tabPanels my still participate in larger Form layouts, etc)

For a FormPanel configured with standardSubmit: true, a form element is created dynamically when the submit method is called.

Hope this clarifies the behaviour.