View Full Version : Where is setValue() ?
ethraza
21 Jul 2007, 12:30 AM
Why all elements in a form have the getValue() but no one have setValue() ?
The only way to set a form value is by setting its on dom?
ex. :-/
Ext.get('textfield').dom.value='banana';
and
Ext.get('selectfield').dom.options['banana'].selected=true;I tried to do a
var cb=new Ext.form.ComboBox({...,transform:'selectfield'});
Ext.get('selectfield').setValue('banana'); But without sucess. :(
So if setvalue don't exist, how to change the selected item from a select combo when I don't know the index, only the value?
ps. Using 1.1rc1
ethraza
21 Jul 2007, 2:01 AM
I did that for now to change the select combo value by value:
setByVal = function(el,str){
var i;
Ext.each(el.dom.options,function(e){
if (e.value == str){
i = e.index;
el.dom.options[i].selected=true
}
})
return i;
}
setByVal(Ext.get('selectfield'),'banana');
But I simple don't beleave that EXTjs don't have a simple way to do that. I only don't know the method to call.
Can some one point me?
tryanDLS
21 Jul 2007, 4:23 AM
http://extjs.com/deploy/ext-1.1-rc1/docs/output/Ext.form.Field.html#setValue
ethraza
21 Jul 2007, 4:35 AM
With cb = new Ext.form.ComboBox({...,transform:'selectfield');
This cb will have setValue, selectByValue and others...
But if after the transform I do a cb = Ext.get('selectfield');
This cb will not have that methods. And the pure html select element, doe's not benefit from setValue too.
So, there is another way to get access to setValue?
(Maybe Ext.get('selectfield').getSomething()?)
Thanks!
tryanDLS
21 Jul 2007, 11:15 AM
Ext.get() returns an Element, not a Field. Think about what you're doing. You need to have reference to a Field, not an Element in order to call a method of the Field class.
ethraza
21 Jul 2007, 8:20 PM
I think I have understand!
I need to define the ComboBox field with a global variable so I can access from anywhere or I need to create a Class thats creates the ComboBox field for me so I can have a private variable inside that Class that I can access later, calling specific function from this class!
Is that?
mdissel
22 Jul 2007, 4:05 AM
You can use Ext.getCmp(<id>) to get a reference to the component (each component is automically registered in a global collections.)
Thanks
Marco
ethraza
22 Jul 2007, 6:25 PM
How I never seed that on docs?
Thank you mdissel!
ethraza
23 Jul 2007, 10:11 AM
Hi!
I tried Ext.getCmp() and it is given an error on Firebug:
Ext.getCpm is not a function
http://beta.ghsix.com.br/averbtransweb/src/inc/javascripts/ext/ext-all.js
Line 94
(This is on Ext-1.1-rc1)
But Ext.ComponentMgr.get() is working great. Thanks!
tryanDLS
23 Jul 2007, 10:33 AM
Look at the error msg - you have typo in your function name.
mattsmith321
23 Jul 2007, 8:00 PM
I think I have understand!
I need to define the ComboBox field with a global variable so I can access from anywhere or I need to create a Class thats creates the ComboBox field for me so I can have a private variable inside that Class that I can access later, calling specific function from this class!
Is that?
I had the same question in this thread a few days ago: http://extjs.com/forum/showthread.php?t=9188
Unfortunately, while I could get access to the field as a Component, it still wasn't subclassed as a DateField so I couldn't call the specific methods that I was looking for.
Powered by vBulletin® Version 4.1.5 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.