PDA

View Full Version : [SOLVED] Setting value of a label of a form field?



thomyorke
3 Jan 2011, 2:15 PM
I have a select field. When the user selects an option, I'd like to change the label of a separate form field based on the option the user selects.

I notice there's no "setValue" method for form fields, but is there a way to programmatically change the label of a formfield?



{
xtype: 'selectfield',
name : 'unitType',
label: 'Unit Type',
options: [
{text: 'Metric', value: 'metric'},
{text: 'Imperial', value: 'imperial'}
],
listeners:{
'change': function(){
var myFields = form.getFields();
if(this.getValue()=='imperial'){
myFields["weight"].label = "Weight (lbs)"; //would like to change label here
}else{
myFields["weight"].label = "Weight (kg)"; //would like to change label here
}
}
}
},
{
xtype: 'numberfield',
name : 'weight',
label: 'Weight (kg)',
required: true
}

adamatvips
3 Jan 2011, 9:48 PM
On a Slider field I can use:


slider.labelEl.setHTML('<span></span>');


so try:

myFields["weight"].labelEl.setHTML('<span>Weight (kg)</span>');

Cheers

thomyorke
4 Jan 2011, 11:28 AM
This worked, thanks for the help :)