PDA

View Full Version : Get BasicForm for field



Hacker-CB
6 Aug 2009, 1:26 AM
How Can I get BasicForm class for field:


...
items: [
new Ext.FormPanel({
items: [{
xtype: 'textfield',
name: 'field1'
},{
xtype: 'textfield',
name: 'field2'
},{
xtype: 'button',
handler: function(b,e){
// I want to get 'field1' here something like
// var form=???? //how to get form here?
// var field1=form.findField('field1');

}
}]
})]
...

Animal
6 Aug 2009, 1:30 AM
Keep a reference to the form.



var myFormpanel;
...
items: [
myFormPanel = new Ext.form.FormPanel({
...


But I'm concerned seeing a FormPanel as a sole item.

Overnesting? Show more code.

Hacker-CB
6 Aug 2009, 1:55 AM
I don't use global variables and IDs.
I found solution with findParentByType:


Ext.apply(Ext.form.VTypes, {

password : function(val, field) {
if (field.initialPassField) {
//var pwd = Ext.getCmp(field.initialPassField);
var formPanel=field.findParentByType('form');
var form=formPanel.getForm();
var pwd = form.findField(field.initialPassField);
return (val == pwd.getValue());
}
return true;
},

passwordText : 'passwords did not match'
});

Animal
6 Aug 2009, 2:10 AM
why did you reply with that?

Keep a reference to the FormPanel.

Also show some code. I am concerned that you are overnesting.

Hacker-CB
6 Aug 2009, 2:14 AM
I need to get form, field belongs to... Anywhere in my code..

I found this solution:


Ext.override(Ext.form.Field, {
getForm : function() {
var form;
this.ownerCt.bubble(function(container){
if (container.form) {
form = container.form;
return false;
}
}, this);

return form;
}
})

Animal
6 Aug 2009, 2:14 AM
<sigh>