PDA

View Full Version : Behavior of form.submit when filefield is present



infernoz
31 Jan 2013, 2:44 PM
Hello,

I have created a form that has as one of its items a file field. I want to submit the file to the server and expect another file as a response.

I am able to set up the above, however when I submit the form, a success message does not get returned and the waitMsg which greys out my entire screen never gets removed. I am pretty sure this is due to the fact that the filefield is in my form. When I comment out this entry, the form is synchronous and waits for the response to return. Obviously I need the filetype to be sent though.

What I'd like to achieve is sending an excel file to the server, get an excel file back as a response from the server and have a synchronous submit that waits for the response from the server. I'd ideally like to use form.submit as it takes advantage of the configs success AND failure, but please let me know the proper way of doing my use case described above.

I am using ExtJS 4.1.0 and here is my form



Ext.define('view.bulk.BulkSearchForm' ,{
extend: 'Ext.form.Panel',
alias: 'widget.bulkSearchForm',
border: false,
layout: 'absolute',

initComponent: function () {
this.callParent(arguments);
},

items: [
{xtype: 'filefield',
name: 'bulksearchfile',
fieldLabel: 'Search File',
labelWidth: 75,
msgTarget: 'side',
allowBlank: false,
anchor: '60%',
x:1, y:5
},
{xtype: 'button', id: 'submitBulkSearchButton', text: 'Bulk Search', width: 100, x:410, y:5,
handler: function() {
var form = this.up('form').getForm();
var processorTypeVar = this.up('form').up().up().up().searchProcessorName;

if (form.isValid()) {

form.submit({scope: this, waitMsg:'Searching', url: '/DataManagementTool/bulksearch.html?returnFileType=filledForm&processorType='+processorTypeVar,
success: function(form, action) {
var messageBox = Ext.Msg.show({
title:'DMT Response',
msg: 'Retrieved Search',
animateTarget: submitButton,
icon: Ext.Msg.INFO,
closable: false
});

setTimeout(function(){
messageBox.close();
}, 2700);

},
failure: function(form, action) {
Ext.Msg.show({
title:'DMT Search',
msg: 'An error has occured while searching for data. Please contact support or try again.',
animateTarget: this,
icon: Ext.Msg.ERROR,
buttons: Ext.Msg.OK
});
}
});


}
}
},
.... Additional Buttons with other functionality.....
]
});


Cheers

infernoz

mitchellsimoens
4 Feb 2013, 12:43 PM
form.submit isn't sync, it's async. The wait message disappears in a callback of the request response.

The form expects JSON back to be something like


{ "success" : true }

That is pretty much a requirement.