PDA

View Full Version : Get form field by name



alupuli
5 Oct 2009, 10:27 PM
got a form named 'MyForm' with textfield named 'NameField'
Which is best method to read textfiel value

tried
Ext.get(''MyForm' ').fields.get('NameField').value which is not really working.

Ext.getDom(id) works if use 'id' instead of 'name'.
But 'id' is really required? can it work with 'name' alone.


Never used 'id' for form elements earlier. and values accessed by document.forms[''].elements[''] instead of document.getElementbyid('') which was expensive.
And 'id' used for div,span,table etc.
Is that the best practice to follow in extjs also considering UI with too many form fields and other html elements.

Nagadev
5 Oct 2009, 10:54 PM
var value = Ext.get(''MyForm").getForm().findField("NameField").getValue(); or
var value = MyForm.getForm().findField("NameField").getValue(); // if MyForm is an valid ext Form object

alupuli
6 Oct 2009, 3:24 AM
One more query related to this.
normally forms can be accessed like document.forms[0] also.
Is there a similar method in ext to get form without specifying name.

Condor
6 Oct 2009, 4:03 AM
The first example one is wrong. It should be:

var value = Ext.getCmp(''MyForm").getForm().findField("NameField").getValue();

developerankit
17 May 2012, 3:59 AM
Hello All

Nothing works to get particular field name from form. My condition is that, I have a form including some text field with same name like 'player[]' (array). Now I want to get each player field to validate.

Nothing is working.... please help to fixed it.


Thanks
Ankit Aggarwal

sword-it
30 May 2012, 5:43 AM
Hi,

You can use find method of form's container to get all same named fields. First, you can get MyForm's container with getComponent method, then use find method.



MyPanel.getComponent(0).find('name','nameField');
or

MyForm.ownerCt.find('name','nameField');

Regards.

efreetant
27 Feb 2013, 5:14 PM
Ext.getCmp(''MyForm").getForm() returns
Object [object Object] has no method 'getForm'
is this 'MyForm' the form id?

willigogs
28 Feb 2013, 12:03 AM
Yes.

sriPrabhu
25 Apr 2013, 2:29 PM
If you get the error Object [object Object] has no method 'getForm' then you might have extended panel.Panel instead of form.Panel. Not 100% sure

Ext.define('MyForm', {
extend: 'Ext.form.Panel', // it shudn't be extend: 'Ext.panel.Panel',
.....
})