Results 1 to 9 of 9

Thread: Get form field by name

  1. #1
    Sencha User
    Join Date
    Sep 2009
    Posts
    81

    Default Get form field by name

    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.

  2. #2

    Default

    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

  3. #3
    Sencha User
    Join Date
    Sep 2009
    Posts
    81

    Default

    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.

  4. #4
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246

    Default

    The first example one is wrong. It should be:
    Code:
    var value = Ext.getCmp(''MyForm").getForm().findField("NameField").getValue();

  5. #5

    Default nothing works

    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

  6. #6
    Sencha User sword-it's Avatar
    Join Date
    May 2012
    Location
    Istanbul
    Posts
    1,335

    Default find method

    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.


    Code:
    MyPanel.getComponent(0).find('name','nameField');
    or
    Code:
    MyForm.ownerCt.find('name','nameField');
    Regards.
    sword-it.com, Sencha Developer House in Turkey - Istanbul University Technopark Suite 204.

  7. #7
    Sencha Premium Member
    Join Date
    Dec 2011
    Posts
    8

    Default

    Ext.getCmp(''MyForm").getForm() returns
    Object [object Object] has no method 'getForm'
    is this 'MyForm' the form id?



  8. #8
    Sencha User
    Join Date
    Jan 2011
    Posts
    549

    Default

    Yes.

  9. #9

    Default May be wrong extend

    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',
    .....
    })

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •