PDA

View Full Version : Label setText() working, but in UI text is not updated.



glafrance
15 Aug 2012, 3:30 PM
I'm using ExtJS 4.0.7 and I have code that uses setText() to change the text of a label.

But after I call setText(), although Chrome dev tools indicates the text has been changed, the UI does not reflect the change.

What should I do?

Thanks in advance.

Farish
15 Aug 2012, 11:26 PM
try component.doLayout() after using component.setText() or refreshing the view of the panel containing that field.

glafrance
16 Aug 2012, 9:13 AM
Label does not have doLayout() and calling doLayout() on its container does not work.

Anyone else?

scottmartin
16 Aug 2012, 9:23 AM
If you upgrade to 4.1.1 (Highly recommended), you could use:



var form = Ext.create('Ext.form.Panel', {
title: 'Contact Info',
width: 300,
bodyPadding: 10,
renderTo: Ext.getBody(),
items: [{
xtype: 'textfield',
name: 'name',
fieldLabel: 'Name',
}]
});

var fld = form.down('textfield');
fld.setFieldLabel('New Name');
?

Scott.

glafrance
16 Aug 2012, 10:09 AM
setText() is working now. I think I was trying to use myLabel.text = "new text" which seemed to work, but did not get refleshed. setText() works now.

scottmartin
16 Aug 2012, 10:19 AM
Correct. You must use a method to update and not a property.

Scott.