svn commit: r1867435 - /ofbiz/ofbiz-framework/trunk/themes/common-theme/webapp/common/js/util/OfbizUtil.js

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1867435 - /ofbiz/ofbiz-framework/trunk/themes/common-theme/webapp/common/js/util/OfbizUtil.js

nmalin
Author: nmalin
Date: Tue Sep 24 08:51:27 2019
New Revision: 1867435

URL: http://svn.apache.org/viewvc?rev=1867435&view=rev
Log:
Fixed: Send upload form with even-update-area doesn't work

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_Objects

Modified:
    ofbiz/ofbiz-framework/trunk/themes/common-theme/webapp/common/js/util/OfbizUtil.js

Modified: ofbiz/ofbiz-framework/trunk/themes/common-theme/webapp/common/js/util/OfbizUtil.js
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/themes/common-theme/webapp/common/js/util/OfbizUtil.js?rev=1867435&r1=1867434&r2=1867435&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/themes/common-theme/webapp/common/js/util/OfbizUtil.js (original)
+++ ofbiz/ofbiz-framework/trunk/themes/common-theme/webapp/common/js/util/OfbizUtil.js Tue Sep 24 08:51:27 2019
@@ -686,10 +686,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);
        }