admin管理员组文章数量:1403443
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
3 Answers
Reset to default 2If 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.
本文标签: javascriptWhat39s the correct way to use setValue on a TextFieldStack Overflow
版权声明:本文标题:javascript - What's the correct way to use setValue on a TextField? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744407321a2604774.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论