javascript - What's the correct way to use setValue on a TextField? - Stack Overflow

I have what appears to be a simple question, but I'm pretty stumped at this point. I'm workin

I have what appears to be a simple question, but I'm pretty stumped at this point. I'm working on some Ext.JS based UI code and I want to change the value of some text inside a form field.

The field is an ext.js.TextField.

I have code like this:

var foo = this.getForm().findField('myFooField');
console.log(foo);
foo.setValue("text different that is different from the default");

If I run this code, "foo" is definitely getting logged to the console, and it's a correct object populated with the values that I'd expect. However, the call to setValue doesn't seem to do anything.

I've put some trace calls before and after setValue to make sure it really does run, and everything seems to be happening without issue. It's just that the UI is not reflecting my change. I've tried calling "setRawValue" as well, but no difference.

Any suggestions? Much appreciated!

I have what appears to be a simple question, but I'm pretty stumped at this point. I'm working on some Ext.JS based UI code and I want to change the value of some text inside a form field.

The field is an ext.js.TextField.

I have code like this:

var foo = this.getForm().findField('myFooField');
console.log(foo);
foo.setValue("text different that is different from the default");

If I run this code, "foo" is definitely getting logged to the console, and it's a correct object populated with the values that I'd expect. However, the call to setValue doesn't seem to do anything.

I've put some trace calls before and after setValue to make sure it really does run, and everything seems to be happening without issue. It's just that the UI is not reflecting my change. I've tried calling "setRawValue" as well, but no difference.

Any suggestions? Much appreciated!

Share Improve this question asked Dec 16, 2011 at 23:52 bitopsbitops 4,3124 gold badges28 silver badges32 bronze badges 3
  • setValue() should work fine. Try getting a reference to the field as an Ext ponent to see if it makes a difference i.e. var foo = Ext.getCmp('myFooField'); – legendofawesomeness Commented Dec 17, 2011 at 0:05
  • What is this on your first line? I'm trying to reproduce your code and getting .getForm() is undefined. – Nick Rolando Commented Dec 17, 2011 at 0:10
  • Could you share the full code of your form? It looks like the issue is related to the code created as the reflection of setValue() is instantaneous and values gets populated in the textbox right away. Also, is there any error thrown? – netemp Commented Dec 19, 2011 at 9:03
Add a ment  | 

3 Answers 3

Reset to default 2

If you are using MVC probably you are trying to change value on render event of a window, for textfields the set value works only on afterRender event.

Your code looks right however I normally use a function like this

Ext.override(Ext.Container, {
setValue: function(c, v) {this.findById(c).setValue(v);},
getValue: function(c) {return this.findById(c).getValue();}
}); 
win.setValue('myFooField', 'Some text');  

I am not sure why your code doesn't work. Check if the below code works.

Ext.getCmp('myFooField').setValue("text different that is different from the default");

Even if this isn't working, then probably you are having the code in wrong place.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744407321a4572699.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信