PDA

View Full Version : How to use getform on toolbar button



vectorbai
5 Dec 2011, 5:05 PM
my code:getForm() is not function


newsForm: {

title: 'New Products',
id: 'Products-form-panel',
layout: 'fit',
bodyPadding: 15,
items: {
title: 'New Produvts Test -Add prod',
layout: 'fit',
frame: true,
items: {
xtype: 'form',
layout:'absolute',
url:'form-save.php',
padding: '0',
border: false,
cls: 'absolute-form-panel-body',

defaultType: 'textfield',
items: [{
x: 0,
y: 5,
xtype: 'label',
text: 'From:'
},{
x: 55,
y: 0,
name: 'from',
hideLabel: true,
anchor:'100%' // anchor width by %
},{
x: 0,
y: 32,
xtype: 'label',
text: 'To:'
},{
x: 55,
y: 27,
xtype: 'button',
text: 'Contacts...'
},{
x: 127,
y: 27,
name: 'to',
hideLabel: true,
anchor: '100%' // anchor width by %
},{
x: 0,
y: 59,
xtype: 'label',
text: 'Subject:'
},{
x: 55,
y: 54,
name: 'subject',
hideLabel: true,
anchor: '100%' // anchor width by %
},{
x: 0,
y: 81,
hideLabel: true,
xtype: 'textarea',
name: 'msg',
anchor: '100% 100%' // anchor width and height
}]

,

buttons: [{
text: 'Submit',
handler: function() {
// The getForm() method returns the Ext.form.Basic instance:
var form = this.up('form').getForm(); //getForm can working !
if (form.isValid()) {
// Submit the Ajax request and handle the response
form.submit({
success: function(form, action) {
Ext.Msg.alert('Success', (action.result.file));
},
failure: function(form, action) {
Ext.Msg.alert('Failed', action.result.msg);
}
});
}
}
}]

////

////
},

dockedItems: [
{
xtype: 'toolbar',
ignoreParentFrame: true,
ignoreBorderManagement: true,
cls: 'absolute-form-toolbar',
items: [
{
text: 'Send',
iconCls: 'icon-send'
},'-',{
text: 'Save',
iconCls: 'icon-save',
handler: function(){

//this.getForm().reset() ;
//------------------------ getForm() not work!!!!
/* Ext.getCmp('Products-form-panel').getForm().submit();*/
//-------------------------getForm() not work!!!!


}
},{
text: 'Check Spelling',
iconCls: 'icon-spell'
},'-',{
text: 'Print',
iconCls: 'icon-print'
},'->',{
text: 'Attach a File',
iconCls: 'icon-attach'
}
]
}
]
}

}

I try many methods but failue.Plz help me solve this problem

mitchellsimoens
6 Dec 2011, 1:50 PM
Had to format your code to be lined up properly...


newsForm: {
title: 'New Products',
layout: 'fit',
bodyPadding: 15,
items: {
title: 'New Produvts Test -Add prod',
layout: 'fit',
frame: true,
items: {
xtype: 'form',
layout:'absolute',
url:'form-save.php',
padding: '0',
border: false,
cls: 'absolute-form-panel-body',
defaultType: 'textfield',
items: [
{
x: 0, //NOT GOOD
y: 5, //NOT GOOD
xtype: 'label',
text: 'From:'
},{
x: 55, //NOT GOOD
y: 0, //NOT GOOD
name: 'from',
hideLabel: true,
anchor:'100%' // anchor width by %
},{
x: 0, //NOT GOOD
y: 32, //NOT GOOD
xtype: 'label',
text: 'To:'
},{
x: 55, //NOT GOOD
y: 27, //NOT GOOD
xtype: 'button',
text: 'Contacts...'
},{
x: 127, //NOT GOOD
y: 27, //NOT GOOD
name: 'to',
hideLabel: true,
anchor: '100%' // anchor width by %
},{
x: 0, //NOT GOOD
y: 59, //NOT GOOD
xtype: 'label',
text: 'Subject:'
},{
x: 55, //NOT GOOD
y: 54, //NOT GOOD
name: 'subject',
hideLabel: true,
anchor: '100%' // anchor width by %
},{
x: 0, //NOT GOOD
y: 81, //NOT GOOD
hideLabel: true,
xtype: 'textarea',
name: 'msg',
anchor: '100% 100%' // anchor width and height
}
],
buttons: [
{
text: 'Submit',
handler: function() {
// The getForm() method returns the Ext.form.Basic instance:
var form = this.up('form').getForm(); //getForm can working !
if (form.isValid()) {
// Submit the Ajax request and handle the response
form.submit({
success: function(form, action) {
Ext.Msg.alert('Success', (action.result.file));
},
failure: function(form, action) {
Ext.Msg.alert('Failed', action.result.msg);
}
});
}
}
}
]
},
dockedItems: [
{
xtype: 'toolbar',
ignoreParentFrame: true,
ignoreBorderManagement: true,
cls: 'absolute-form-toolbar',
items: [
{
text: 'Send',
iconCls: 'icon-send'
},
'-',
{
text: 'Save',
iconCls: 'icon-save',
handler: function() {}
},
{
text: 'Check Spelling',
iconCls: 'icon-spell'
},
'-',
{
text: 'Print',
iconCls: 'icon-print'
},
'->',
{
text: 'Attach a File',
iconCls: 'icon-attach'
}
]
}
]
}
}

What does this.up('form') return? You should use the formpanel xtype, form has been deprecated.