Fbo
Fbo

Reputation: 172

Component selector in Extjs 4

I'm trying to select multiple objects (2 labels & 2 textfields) that are located in a panel. I gave these components a property (changeVisibility: true).

So the thing i'm trying to accomplish here is quite simple: when the user checks the checkbox, all the components with the property (changeVisibility:true) should become invisible. So in my controller i'm trying to select these components but i'm unable to accomplish this thusfar.

Help is much appreciated!

Code of my panel:

Ext.define('Edocs.view.wizard.card-2.content.mobile-password.Panel', {
extend : 'Ext.FormPanel',
alias : 'widget.mobilePassword',
layout : {
    type : 'vbox',
    pack: 'center'
},
bodyStyle:{"background-color":"beige"},
border:false,
defaults:{

    width: '100%'     
},

items: [{        
    xtype           : 'checkboxfield',
    boxLabel        : 'Enable mobile (iphone) accesibility',
    boxLabelAlign   : 'before',
    name            : 'enableMobile',
    inputValue      : '1',
    id              : 'cbxMobile',
    itemId          : 'cbxMobile'

},{
    xtype: 'label',
    text: "Please enter a password to connect to the platform by mobile (iphone/ipad)",
    style: 'font-weight:bold;',
    changeVisibility :true
},{
    xtype: 'textfield', 
    name: 'mobilePassword',
    id: 'txtMobilePassword',
    inputType: 'password'  ,
    changeVisibility :true
    //width: '100%'
},{
    xtype: 'label',
    text: "Confirm password",
    style: 'font-weight:bold;',
    changeVisibility :true
},
{
    xtype: 'textfield', 
    name: 'mobilePasswordConfirm',
    itemId: 'txtMobilePasswordConfirm',
    inputType: 'password'  ,
    vtype: 'password',
    initialPassField: 'txtMobilePassword',
    changeVisibility :true
}],


initComponent : function() {

    Ext.apply(this, {})
    this.callParent(arguments);
}
});

This is the function in my controller (this function is called on the change event of the checkbox):

addMobilePassword : function(checkbox) {
    var items = checkbox.up().down('mobilePassword[changeVisibility=true]');
    if (checkbox.checked){
        for (var i in items){
            items[i].setVisible(false);
        }
    }
}

I'm having troubles with this selector:

 var items = checkbox.up().down('mobilePassword[changeVisibility=true]');

If anyone could give me some advice on how to select these components.

Thanks!

Upvotes: 1

Views: 6882

Answers (2)

U and me
U and me

Reputation: 740

down() will find the first matched descendant of the container. So I think you should try:

checkbox.up().down('mobilePassword').query('label[changeVisibility], textfield[changeVisibility]')

or briefer

checkbox.up().query('label[changeVisibility], textfield[changeVisibility]')

Upvotes: 4

sha
sha

Reputation: 17860

Try query('[changeVisibility=true]')

Upvotes: 0

Related Questions