extjs4.1

Disable a extjs xtype button bases on a javascript variable value


I have a button which I need to be disabled if the javascript variable is 'user'. I am not sure how to go about it. This is what I tried :

var loggedin_role = '<?php echo "$user_role"; ?>';          

                 xtype: 'button',
                if(loggedin_role =='user') {
                    disabled:true
                },
                text: 'Save',

Solution

  • Using PHP

    You can do it using simple php logic.

    <?php if ($user_role=='user'): ?>
    disabled: true;
    <?php endif; ?>
    

    Using ExtJS event

    You can use any event handlers. activate( Ext.Component this, Object eOpts )

    var loggedin_role = '<?php echo "$user_role"; ?>';          
    
            xtype: 'button',
            listeners : {
                activeate: function(btn, eOpts){
                    if(loggedin_role =='user') {
                        btn.disable();
                    }
                }
            },