hide and show item

zied jouini picture zied jouini · Mar 14, 2012 · Viewed 25.9k times · Source

My problem this time is to make an item appear and disappear. I know it is done with hide() and show() but I do not know how? Here is my code. I want to make a xtype appear : "datepickerfield" when I select the "Appointment" in "selectfield"

App.views.Bankingrendezvous = Ext.extend(Ext.Panel, {

items: [{
xtype: 'formpanel',
id: 'form',
fullscreen: true,
scroll: 'vertical',
items: [{

       xtype: 'fieldset',
       title: 'Information & Appointment',
    },
    {
        xtype: 'selectfield',
        id: 'request',
        label: 'You need',
        options: [ 
        {   
            text: 'Appointment',
            value: 'Appointment'
        },
        {   
            text: 'Information',
            value: 'Information',

        }]



    },
    {
xtype: "datepickerfield",
id: "startDate",
label: "when",
picker: { yearFrom: 2012, yearTo: 2020} 

    },}]
     }]
     });
    Ext.reg('Bankingrendezvous', App.views.Bankingrendezvous);

thank you. i tried as you say :

  {
xtype: "datepickerfield",
id: "startDate",
label: "when",
picker: { yearFrom: 2012, yearTo: 2020}
    this.items.getAt().hide();
 },

but it doesn't work.


items: [{
xtype: 'formpanel',
 id: 'form',
fullscreen: true,
scroll: 'vertical',
items: [{

       xtype: 'fieldset',
       title: 'Information & Appointment',
    },
    {
        xtype: 'selectfield',
        id: 'request',
        label: 'You need',
        options: [ 
        {   
            text: 'Appointment',
            value: 'Appointment'
        },
        {   
            text: 'Information',
            value: 'Information',
        }],
     listeners: {
         function()
                  {
                    if (Ext.getCmp('request').getValue() == 'Information')
                      {
                        Ext.getCmp('startDate').hide();
                      }
                  }
               },


    },
     {
 xtype: "datepickerfield",
 id: 'startDate',
 label: "when",
 picker: { yearFrom: 2012, yearTo: 2020},        
      },

i tried this but it doesnt work

Answer

sna19 picture sna19 · Mar 15, 2012

You can use either of two methods: hide()/show() or setVisible(true/false).

If you want to access your items inside the object (for example, inside initComponent() event), use the following clause:

this.items.getAt(<index of item>).hide();
this.items.getAt(<index of item>).show();

In order to set access the element out of class you do it by using getCmp() method:

var el = Ext.getCmp("elementID");

and then access the item and set it's visibility.

el.items.getAt(<index of item>).setVisible(false); // hide
el.items.getAt(<index of item>).setVisible(true); // show