PDA

View Full Version : standardSubmit issue



nathanblogs
15 Feb 2010, 10:37 PM
Hi,

I currently have a formpanel which contains some fields that I use to search, the search results are then put into a gridpanel. I am now trying to add an export button, but since you can't get a csv export from a standard submit I am trying to create a hiden formpanel which I will fill with the search params and query the server. To do this I believe I need to use the standardSubmit options but I can get the examples to work eg: http://www.extjs.com/learn/Manual:Forms:BasicForm:standardSubmit .

This is my code, it is a direct copy and paste from the example but I can't get it to submit and it just throws and error ( the error is listed at the bottom ).



var exportForm = new Ext.FormPanel({
renderTo: document.body,
labelAlign: "side",
frame: true,
autoHeight: true,
waitMsgTarget: true,
standardSubmit: true,
baseParams: {
id: 1
},
url: "myProcess.php",
title: "My Form",
items: [{
title: "Name Fields",
xtype: "fieldset",
autoHeight: true,
defaults: {
hideLabel: true,
labelSeparator: ""
},
items: {
xtype: "textfield",
name: "userName"
}
}],
buttons: [{
text: "Save",
id: 'hidden_button',
handler: function () {
var O = this.ownerCt;
if (O.getForm().isValid()) {
if (O.url) O.getForm().getEl().dom.action = O.url;
if (O.baseParams) {
for (i in O.baseParams) {
O.add({
xtype: "hidden",
name: i,
value: O.baseParams[i]
})
}
O.doLayout();
}
O.getForm().submit();
}
}
}]
});
And I call it from the other formpanel by doing



Ext.getCmp('hidden_button').handler();
However firebug is giving me the error:



O.getForm is not a function
help please ?

I am using v3.1.1

Eugen_
15 Feb 2010, 11:00 PM
Hi nathanblogs,





buttons: [{
text: "Save",
id: 'hidden_button',
handler: function () {
var O = this.ownerCt.ownerCt;

nathanblogs
15 Feb 2010, 11:41 PM
Hi nathanblogs,

Dammit, I should of been able to combine the broken code of http://www.extjs.com/deploy/dev/docs/?class=Ext.form.BasicForm with the broken code of http://www.extjs.com/learn/Manual:Forms:BasicForm:standardSubmit to get it working :(.

Thanks for the help.

Eugen_
15 Feb 2010, 11:57 PM
There is a bug in standartSubmit example. :-/

nathanblogs
16 Feb 2010, 6:15 PM
Here is my solution, probably not the best, hopefully it will help someone else.




var exportForm = new Ext.FormPanel({
renderTo: document.body, // This is required, wouldn't work without
standardSubmit: true,
baseParams: {},
url: 'exportUrl',
buttons: [{
id: 'hidden_button',
handler: function () {
var form = this.ownerCt.ownerCt;

if (form.getForm().isValid()) {
if (form.url) form.getForm().getEl().dom.action = form.url;

if (form.baseParams) {
// searchPanel is my panel with all the formfields.
searchPanel.form.items.each(function(){
form.add({
xtype: 'hidden',
name: this.getName(),
value: this.getValue()
});
});
form.doLayout();
}

form.getForm().submit();
}
}
}]
});

And I just call it from a button on the formpanel like so:



Ext.getCmp('hidden_button').handler();

Animal
17 Feb 2010, 12:51 AM
I don't understand why you don't just make an Ajax request?

nathanblogs
17 Feb 2010, 12:58 AM
I don't understand why you don't just make an Ajax request?

I need to return a csv file, as far as I am aware you can't do that with an ajax request ?

Eugen_
17 Feb 2010, 1:57 AM
I need to return a csv file, as far as I am aware you can't do that with an ajax request ?
Do you need to download only the csv file? You can try to use this:



handler: function() {
document.location = downloadUrl + '?' + yourVariables;
}




header('Content-Type: text/csv');

Animal
17 Feb 2010, 2:13 AM
OK, if you need to submit something and receive a file, then submitting a form is the correct way.

nathanblogs
17 Feb 2010, 5:44 AM
Do you need to download only the csv file? You can try to use this:



handler: function() {
document.location = downloadUrl + '?' + yourVariables;
}


header('Content-Type: text/csv');


The problem is getting the data back not sending the query, the solution I have works so it will have to do for now.


OK, if you need to submit something and receive a file, then submitting a form is the correct way.

Yeah that's what I need.