[Xsltforms-support] form submission via JavaScript
Brought to you by:
alain-couthures
From: Adam M. <Ada...@gm...> - 2013-01-17 07:33:46
|
Hello Alain and everyone :) I've experimented with doing form submission via JavaScript, and it's working well for me, *except* that I've made an edit to *xsltforms.js*. So I'd like to show my use case, and show the edit I made to the code, and then get some feedback. *1. MY USE CASE* For now, I find it most convenient to handle the submission in JavaScript. If submission fails, the server (in my application) will provide a JSON response containing an exception. I find it simplest (for now) to handle the submission request in JavaScript (with jQuery which is running in the parent document). Xsltforms provides for doing this, but I ran into a problem where it was appending url-encoded instance data to the URL, which wasn't appropriate in my use case. Here's the submission element from my form: <xf:submission id='submit' method='get' relevant='true' replace='instance' serialization='application/xml' action='javascript:submit(ser)' /> Here you can see the whole top level of my form, which includes the JavaScript for submission: http://pastebin.com/N2KCAT5t *2. MY CODE CHANGE* * * At revision 565, my change is to line 4105 of *xsltforms.js* (split onto multiple lines here)*:* if ((method === "get" || method === "delete") && this.serialization !== "none" *&& action.substr(0, 11) !== 'javascript:'* && action.substr(0, 9) !== "opener://" && action.substr(0, 8) !== "local://") { The effect of the change is to skip adding the url-encoded arguments, for a 'get' or 'delete' submission where the action is JavaScript. This way I can pass XML to my JavaScript submission function, and avoid having the action mangled to something like 'javascript:submit(ser)* ?var1=val1&var2=val2*'. *3. YOUR THOUGHTS?* * * Is my change OK to integrate into mainline source? Or maybe there's a better way to go? Thanks very much, /Adam |