PDA

View Full Version : get an item in form panel



hieu79vn
16 Jul 2012, 6:29 AM
Hi

I have a textfield in a form panel. How can I get this textfield and change it value?

Thank you

redraid
16 Jul 2012, 6:41 AM
Add itemId to field:


// form conf
{
itemId: 'myField',
xtype: 'textfield'
}

after this you can query this field from form instance:


var form = ..., // get form instance
field = form.down('#myField');

field.setValue('new value');

hieu79vn
16 Jul 2012, 6:56 AM
thank you for your reply.
The ItemID is unique only in an instance of form?
because I have many instance of form

Thanks

scottmartin
16 Jul 2012, 7:03 AM
The id will unique to the form it belongs to

Scott.

redraid
16 Jul 2012, 7:10 AM
itemId's are an index to the container's internal MixedCollection, the itemId is scoped locally to the container - http://docs.sencha.com/ext-js/4-1/#!/api/Ext.AbstractComponent-cfg-itemId

hieu79vn
16 Jul 2012, 11:22 PM
Thank you Scott and Redraid
Have a nice day

hieu79vn
17 Jul 2012, 12:06 AM
Sorry I have another problem
I have a form panel

Ext.define('ThreadReplyHeader', {
extend: 'Ext.form.Panel',
alias: 'widget.threadreplyheader',

initComponent: function () {
Ext.apply(this, {

items: [
{
xtype: 'container',
anchor: '100%',
layout: 'column',
items: [
{
xtype: 'textfield',
fieldLabel: '<%=GetText("subject",false)%> ',
name: 'thread_label',
columnWidth: 1
}
]
}
],
...other items tp call showUserlist fucntion
showUserList: function(){
this.userlistwindow = Ext.create('widget.userlistwindow',{
record: this.record,
listeners: {
scope: this,
beforeclose: this.onBeforeClose
}
}); this.userlistwindow.show();

},
onBeforeClose: function(panel){
var tfTo = this.up('form').getForm().down('#tfSendTo'); // this one give an errror Cannot call method 'getForm' of undefined
//I tried this one var tfTo = this.getForm().down('#tfSendTo') but also error // this one give an errror Object [object Object] has no method 'down' //I tried alert (this.self.getName()); result: ThreadReplyHeader
}
Do you know why I cannot reference to the form Panel or to call .down('#tfSendTo') ?

Thank you

redraid
17 Jul 2012, 12:45 AM
onBeforeClose function member of form panel:

var tfTo = this.down('#tfSendTo');

hieu79vn
17 Jul 2012, 3:01 AM
I found the problem
var tfTo = this.getForm().findField('send_to');


Thank you