PDA

View Full Version : How to hide form element labels on hide()? SOLVED



borg
22 Jul 2009, 7:00 AM
When you set a TextField or any form item to hidden: true in Ext-2.2 you had to include the following code in order for the TextField's label to be hidden along with it when using show() and hide(). What do I have to do to make it work with Ext-3?



// remove spaces for hidden elements and make show(), hide(), enable() and disable() act on the label. don't use hideLabel with this
Ext.override(Ext.layout.FormLayout, {
renderItem: function(c, position, target) {
if (c && !c.rendered && c.isFormField && c.inputType != 'hidden') {
var args = [
c.id, c.fieldLabel,
c.labelStyle||this.labelStyle||'',
this.elementStyle||'',
typeof c.labelSeparator == 'undefined' ? this.labelSeparator : c.labelSeparator,
(c.itemCls||this.container.itemCls||'') + (c.hideLabel ? ' x-hide-label' : ''),
c.clearCls || 'x-form-clear-left'
];
if(typeof position == 'number') {
position = target.dom.childNodes[position] || null;
}
if (position) {
c.formItem = this.fieldTpl.insertBefore(position, args, true);
}
else {
c.formItem = this.fieldTpl.append(target, args, true);
}
c.actionMode = 'formItem';
c.render('x-form-el-'+c.id);
c.container = c.formItem;
c.actionMode = 'container';
}
else {
Ext.layout.FormLayout.superclass.renderItem.apply(this, arguments);
}
}
});
Ext.override(Ext.form.TriggerField, {
actionMode: 'wrap',
onShow: Ext.form.TriggerField.superclass.onShow,
onHide: Ext.form.TriggerField.superclass.onHide
});

SOLUTION:


Ext.override(Ext.layout.FormLayout, {
renderItem : function(c, position, target){
if(c && !c.rendered && (c.isFormField || c.fieldLabel) && c.inputType != 'hidden'){
var args = this.getTemplateArgs(c);
if(typeof position == 'number'){
position = target.dom.childNodes[position] || null;
}
if(position){
c.formItem = this.fieldTpl.insertBefore(position, args, true);
}else{
c.formItem = this.fieldTpl.append(target, args, true);
}
c.actionMode = 'formItem';
c.render('x-form-el-'+c.id);
c.container = c.formItem;
c.actionMode = 'container';
}else {
Ext.layout.FormLayout.superclass.renderItem.apply(this, arguments);
}
}
});