PDA

View Full Version : How to empty textfield when label is pushed twice



hudi1
4 Jun 2013, 10:35 PM
Hi I have easy form with textfields and labels:

Is there option s to add function when I double click on label then I want to empty this textfield

Thx for help


xtype : 'form',
bodyPadding : 10,
header : false,
title : 'Personal Data',
defaults : {
anchor : '100%',
labelWidth : 120
},
items : [ {
xtype : 'textfield',
itemId : 'firstName',
name : 'firstName',
fieldLabel : 'First Name'
}, {
xtype : 'textfield',
itemId : 'lastName',
name : 'lastName',
fieldLabel : 'Last Name'
}, {
xtype : 'datefield',
format : 'd.m.Y',
itemId : 'dateOfBirthFrom',
name : 'dateOfBirthFrom',
fieldLabel : 'Date of Birth from'
}, {
xtype : 'datefield',
format : 'd.m.Y',
itemId : 'dateOfBirthTo',
name : 'dateOfBirthTo',
fieldLabel : 'Date of Birth to'
}, {
xtype : 'textfield',
itemId : 'ssn',
name : 'ssn',
fieldLabel : 'SSN'
}, {
xtype : 'combobox',
itemId : 'gender',
name : 'gender',
fieldLabel : 'Gender',
store : [ '', 'MALE', 'FEMALE' ]
} ]

hudi1
5 Jun 2013, 3:47 AM
probably not the best solution but it works. Any idea how to improve it ?


this.control({
"form > textfield" : {
render : this.addDblClickEvent
}
});
},

addDblClickEvent : function(textfield, e, eOpts) {
textfield.getEl().on('dblclick',
Ext.bind(this.onTextfieldClick, this, [textfield], true));
},

onTextfieldClick : function(event, html, opt, textfield) {
if (html instanceof HTMLLabelElement) {
textfield.reset();
}
},

jasewell
5 Jun 2013, 2:57 PM
I was thinking something like this:


defaults: {
listeners: {
render: function(me) {
if (me.xtype == 'textfield')
me.el.down('.x-field-label-cell').addListener('dblclick', function() { me.setValue(); });
}
}
},