Results 1 to 4 of 4

Thread: Alternative way for Ext.getCmp

  1. #1
    Sencha User
    Join Date
    Aug 2012
    Location
    Pune, India
    Posts
    78
    Answers
    5
    Vote Rating
    0
      0  

    Default Alternative way for Ext.getCmp

    Hi,

    I have lot of controls in ExtJS form which are placed inside different panels. Following is my code for one of the panel-

    var pnlCIRT = new Ext.Panel({
    region: 'south',
    id: 'detailpanel',
    collapsible: false,
    autoScroll: true,
    layout: 'vbox',
    height: 300,
    title: 'CIRT Details',
    items: [{
    xtype: 'fieldcontainer',
    layout: 'hbox',
    items: [{
    xtype: 'displayfield',
    id: 'dfdate',
    name: 'date',
    fieldLabel: 'Date',
    labelWidth: 120,
    value: date,
    width: 143
    }, {
    xtype: 'splitter',
    width: 200
    }, {
    xtype: 'displayfield',
    id: 'dfcirtnumber',
    name: 'cirtnumber',
    fieldLabel: 'CIRT Number',
    value: CIRTNumber,
    labelWidth: 180,
    width: 120
    }]

    At this point; I'm using Ext.getCmp('dfcirtnumber').setValue(results.CIRTNumber); to read the control and set value.

    I think; Ext.getCmp is NOT a good practice to read and set control values if there are huge amount of controls used within a form.

    Please let me know if there is any way to get and set value of control using the panel name so that I can directly get control from the panel itself.
    Thanks, Pravin

  2. #2
    Sencha User
    Join Date
    Dec 2009
    Location
    Enschede, The Netherlands
    Posts
    327
    Answers
    16
    Vote Rating
    14
      1  

    Default

    If possible, always try to work relatively. For example if you need to update a form title on a button click, work relatively from the button:

    Code:
    onButtonclick: function(button) {
      var form = button.up('myformXtype'),
        field = form.down('textfield[name=someName]');
    
      form.doStuff();
      field.doOtherStuff();
    }
    If you really need to work globally you can use Ext.ComponentQuery which can also search for a component type with some specific attributes removing the need for globally unique id's

  3. #3
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Answers
    3931
    Vote Rating
    1272
      0  

    Default

    Quote Originally Posted by flanders View Post
    If possible, always try to work relatively.
    Wow, that's a hell of a lot better way to explain it than what I was always trying

    +1 for the suggestion!
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  4. #4
    Sencha User
    Join Date
    Aug 2012
    Location
    Pune, India
    Posts
    78
    Answers
    5
    Vote Rating
    0
      0  

    Default

    Thanks for suggestions.
    Thanks, Pravin

Posting Permissions

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