View Full Version : Setting input value doesn't work for me.

14 Mar 2011, 11:48 AM
I know this is probably one of those "This is not how it works in Ext JS" things, but I had trouble setting a value on an input field and I'd appreciate some feedback as to why this wasn't working.


<input type="text" name="startTime" value="9:00 AM" id="startTime" />My two attempts to change the value:

Ext.getCmp('startTime').setValue(getText(thumb));What actually worked:

$('#startTime').val(getText(thumb));Go jQuery!

EDIT: Oops, forgot to mention that getText(thumb) returns a text string and it's working just fine.

The form was defined in standard html (i.e. <form ...></form>).
My question is, did I not use the correct code to try to update my input field?


14 Mar 2011, 12:26 PM
setValue() (to my knowledge) will only work with ExtJS created form elements.

new Ext.form.TextField({
id: 'startTime',
name: 'startTime'

Ext.getCmp('startTime').setValue('9:00 AM');

14 Mar 2011, 12:27 PM
You may also be able to do Ext.get('startTime').update() but I haven't tried it...

Alternatively you can find the DOM element in the Ext.get() call and set the value that way.

14 Mar 2011, 1:01 PM
Thank you bryall, I suspected this to be the case, at least for Ext.getCmp. I have verified that I can retrieve the DOM object, but the setValue function does not work on it, probably (as you stated) because it's not an Ext component. This is one of those times that I'm happy that Ext JS and jQuery work so well side by side. It makes my world a little easier when things don't go right. :)