PDA

View Full Version : Textfield Labels - Disable



ajmPal
11 Dec 2012, 10:52 AM
Is there a way to disable the textfield label ? When I set disabled:true on a textfield, only the text box is disabled.


{xtype: 'textfield', id'genText', disabled: true, fieldLabel: 'Text Query' , width: 800, style: 'margin-left: 50px; labelStyle: 'width:140px;'},


Tony Mariella

mitchellsimoens
13 Dec 2012, 7:41 AM
Try this (special stuff in red):


var origDisabledFn = Ext.form.Field.prototype.onDisable

Ext.form.Field.prototype.onDisable = function() {
origDisabledFn.call(this);

this.label.addClass(this.disabledClass);
};

var origEnabledFn = Ext.form.Field.prototype.onDisable

Ext.form.Field.prototype.onEnable = function () {
origEnabledFn.call(this);

this.label.removeClass(this.disabledClass);
};

Ext.onReady(function() {

new Ext.form.FormPanel({
renderTo : document.body,
items : [
{
xtype : 'textfield',
fieldLabel : 'Test',
disabled : true
},
{
xtype : 'button',
text : 'Toggle Text field',
handler : function(btn) {
var field = btn.previousSibling(),
disabled = field.disabled || false;

field[disabled ? 'enable' : 'disable']();
}
}
]
});

});