Greg Lafrance
Greg Lafrance

Reputation: 809

In Extjs 4.2 why does setValue() not update a textfield?

The following code seems to change the textfield value, because the AFTER alert shows the value as changed.

But when you look at the textfield in the form, it is blank???

var selectedItem = JSON.parse(CommonUtil.getSelectedRows(this.getSettingGrid()))[0];
alert("BEFORE: " + this.getSettingVcenter().queryById('txtName').getValue());
this.getSettingVcenter().queryById('txtName').setValue(selectedItem.name);
alert("AFTER: " + this.getSettingVcenter().queryById('txtName').getValue());

Upvotes: 0

Views: 3363

Answers (2)

user3629411
user3629411

Reputation: 1

Making the textfield visible by using the setter method setVisible(true) after setting the value, made it show. I tried using mytextField.hidden=false; but did not work in afterrender.

Upvotes: 0

code4jhon
code4jhon

Reputation: 6044

The only reason I could think were that is possible is that you are not modifying the actual textfield but a copy of the object or something else.

To fetch components in Ext you should use:

var myTextField = Ext.ComponentQuery.query('textfield[itemId=someId]')[0];

myTextField.setValue("newValue");  //This is guaranteed to work

Also use:

console.log(yourObject); //this is to see the xtype of what your are modyfing the value, is it really the textfield?`

http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.ComponentQuery-method-query

Upvotes: 2

Related Questions