Author: nmalin
Date: Tue Sep 24 09:00:35 2019
New Revision: 1867438
URL:
http://svn.apache.org/viewvc?rev=1867438&view=revLog:
Fixed: Send upload form with even-update-area doesn't work (Backport from trunk)
(OFBIZ-11207)
When you create a xml form with upload as type, you can't use on-event-update-area element to submit it by ajax.
Otherwise, OFBiz return an error message on 'uploadFile is empty.
To solve it, we analyze the enctype's form before submit it to move on FormData instead a direct serialize [1]
example form where the problem has been present
****
<form name='AddNicelyFile' type='upload' target='CreateNicelyFile'>
<field name='uploadedFile' title='File'><file/></field>
<field name='addButton'><submit/></field>
<on-event-update-area event-type='submit' area-id='window' area-target='FileDisplaying'/>
</form>
****
Thanks to Samuel Tregouet for this fix
[1]
https://developer.mozilla.org/en-US/docs/Web/API/FormData/Using_FormData_ObjectsModified:
ofbiz/ofbiz-framework/branches/release17.12/themes/common/webapp/common/js/util/OfbizUtil.js
Modified: ofbiz/ofbiz-framework/branches/release17.12/themes/common/webapp/common/js/util/OfbizUtil.js
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release17.12/themes/common/webapp/common/js/util/OfbizUtil.js?rev=1867438&r1=1867437&r2=1867438&view=diff==============================================================================
--- ofbiz/ofbiz-framework/branches/release17.12/themes/common/webapp/common/js/util/OfbizUtil.js (original)
+++ ofbiz/ofbiz-framework/branches/release17.12/themes/common/webapp/common/js/util/OfbizUtil.js Tue Sep 24 09:00:35 2019
@@ -533,10 +533,26 @@ function ajaxSubmitFormUpdateAreas(form,
waitSpinnerHide();
}
+ var $form = jQuery("#" + form),
+ data = null,
+ processData = true,
+ enctype = $form.attr("enctype"),
+ contentType = "application/x-www-form-urlencoded; charset=UTF-8";
+
+ if (enctype && enctype.indexOf("multipart") !== -1) {
+ data = new FormData($form[0]);
+ contentType = false;
+ processData = false;
+ } else {
+ data = $form.serialize();
+ }
+
jQuery.ajax({
type: "POST",
- url: jQuery("#" + form).attr("action"),
- data: jQuery("#" + form).serialize(),
+ contentType: contentType,
+ url: $form.attr("action"),
+ data: data,
+ processData: processData,
success: function(data) {
updateFunction(data);
}