1. #1
    Sencha User
    Join Date
    Sep 2009
    Posts
    81
    Vote Rating
    0
    alupuli is on a distinguished road

      0  

    Default Get form field by name

    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
    Ext User
    Join Date
    Aug 2009
    Posts
    30
    Vote Rating
    0
    Nagadev is on a distinguished road

      0  

    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
    Vote Rating
    0
    alupuli is on a distinguished road

      0  

    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 - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    91
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


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

  5. #5
    Sencha User
    Join Date
    Apr 2012
    Posts
    24
    Vote Rating
    0
    developerankit is on a distinguished road

      0  

    Default nothing works

    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 - Community Support Team sword-it's Avatar
    Join Date
    May 2012
    Location
    Istanbul
    Posts
    1,333
    Vote Rating
    85
    sword-it is a jewel in the rough sword-it is a jewel in the rough sword-it is a jewel in the rough sword-it is a jewel in the rough

      0  

    Default find method

    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
    7
    Vote Rating
    0
    efreetant is on a distinguished road

      0  

    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
    544
    Vote Rating
    52
    willigogs is a jewel in the rough willigogs is a jewel in the rough willigogs is a jewel in the rough

      0  

    Default


    Yes.

  9. #9
    Sencha User
    Join Date
    Apr 2013
    Posts
    1
    Vote Rating
    0
    sriPrabhu is on a distinguished road

      0  

    Default May be wrong extend

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