@surangak @harsha89 @burke @dkayiwa @mogoodrich
@darius Sorry for the brief question. Here is a detailed version of what I have done
What I have done? I have analyzed how the old form submit works by monitoring the HTTP traffic of the web page. I have also done the same for the new UI. All form uploads are done using a http POST request with multipart/form-data enctype. But in the case of the new UI, all POST parameters except ones which contain files are being sent to the server. I then analyzed the reason for this.
How HTML form submit works. On the old UI, HTML form submit worked using just a plain HTTP POST request. But in the new UI this is handled using Javascript (on the htmlform.js script). Where multiple pre submit checks are performed and then the form data are submitted to the server using an Ajax request. Internally the formdata is serialized using the form.serialize() method provided by jQuery (https://api.jquery.com/serialize/) and sent to the server using an Ajax POST request also using jQuery.
Why Ajax is not working? In the new UI, the form.serialize() method that is being used does not work for “file” input types. Hence when I monitor requests made by the page when submitting the form I see that only other input types (“text” for example) are sent to the server but not the “file” types. Hence file uploading fails.
Suggestions Use the new XHR2 specification(http://www.html5rocks.com/en/tutorials/file/xhr2/) which supports file uploading via ajax requests. I tried this by replacing the ajax request in the htmlform.js file - but it seems that the Spring backend does not support this type of requests yet? (I have yet to verify that). And the server gives a HTML 500 error with the following stack trace. http://pastebin.com/C9jh8t5y
How to replicate this
1 ) I edited the htmlForm.js file inthe HTMLFormentryUI module in OpenMRS and re build it. replace the htmlForm.js file with the file here : https://github.com/surangak/HguSriLanka/blob/master/htmlForm.js in HTMLFormEntryUI module (Try with 1.5 version since that is the latest version in the latest standalone )
-
Copy the hgu omod file to mdoules folder ( it has the jquery.form.js file required to the ajax calls) https://github.com/surangak/HguSriLanka/tree/master/hgu/omod/target
-
Create an HTML form using this form : https://github.com/surangak/HguSriLanka/blob/master/upload.html
-
Try uploading an image using the new UI of OpenMRS
then u will realize it would not work.
Please suggest me how to tackle this issue.
Thank you