PDA

View Full Version : Accessing form fields from button handlers



randomuser01
12 Sep 2008, 5:14 AM
What is the correct way to access the form from button handlers?


MyApp.MyPopup = Ext.extend(Ext.FormPanel, {
Record:null,
.................
.................
items: [{
fieldLabel: 'ID', id:'_id'
}]
,buttons: [{
text: this.Record.Field == 'foo' ? 'bar' : 'none', // works
var id = Ext.get('_id').dom.value // is this the only way?

}

Thanks

evant
12 Sep 2008, 5:15 AM
You need to set the scope of the handler.

neo4200
12 Sep 2008, 5:55 AM
Hi,

I have an almost similar problem

I have an object extending Ext.FormPannel

I declare all fields as class variable at the beginning of my class

eg :

APP.SearchContactForm= Ext.extend(Ext.FormPanel, {
nomField:null,
......then i assign my class variables like this :


this.nomField = new Ext.form.TextField({
id:'nomField',
....
});then i apply all properties to my extended object in the initComponent function


Ext.apply(this,{ items:[
layout:'form',
items:[this.nomField],
buttons:[{
text:'submit',
handler:this.submit,
scope:this
]}
});in the submit function i'm doing a simple processing like


alert(this.nomField.getValue())and it always displays 'undefined' except if i set a initial value like this


this.nomField = new Ext.form.TextField({
id:'nomField',
value : 'init'
});but even if i change this value by typing something different in the field it still displays 'init' in the alert.

the only way to make it works is calling


Ext.get('nomField').getValue()What's wrong with my approach.

Sorry if it's a silly question, i started Ext like 2 days ago. and it's my first application.

here is the file containing the source code :

http://cm.mcarnolds.be/inc/js/application/ContactGrid.js

thx for the help

randomuser01
12 Sep 2008, 9:11 AM
Hi,

Not sure I'm following you.


buttons: [{
text: this.RFQRecord.Price == '0' ? 'Quote' : 'Accept',
handler:this.OnAccept(), scope:this
},{
text:'Ignore', handler:this.OnIgnore(), scope:this
},{
text:'Close', handler:this.OnCancel(), scope:this
}
},
OnCancel: function(oevent) {
var form = this.form;
}
]

still gives me an undefined.

Also, it seems from these handlers, I can no longer get the parent window to close. Any ideas how I can do this?

var wnd = Ext.getCmp('ViewPopupWnd');
wnd.close();

randomuser01
12 Sep 2008, 9:32 AM
Sorry, I forgot to add that the place where I need to get to the control is when I want to iterate over a grid with checkboxes to allow multi-select.


xtype: 'grid'
,ds:allDS
,id:'_ctl
,name:'_ctl
,cm: new Ext.grid.ColumnModel([
sm2,
{id:'item',header: 'Name',sortable: true,locked:false,dataIndex: 'item'}
])
,sm:sm2
,viewConfig: {forcefit:true}
,frame:true