Thread: [Xsltforms-support] form submission via JavaScript, co-existence w/ jQuery
Brought to you by:
alain-couthures
From: Adam M. <Ada...@gm...> - 2013-03-24 13:40:24
|
Hi, << This time I'm posting in plain text, which should work better! >> A few months ago I asked for some advice about invoking JavaScript to handle form submission. I'd like to restate the problem I encountered, share my work-around, and ask again for input. I wanted to pass the instance data (serialized as xml) to a JavaScript function, and let it handle the submission from there. The problem I encountered is that I could only use the 'get' submission method with JavaScript, and with 'get' the instance data would be URL-encoded and appended to the 'action', which is a problem if the action is 'javascript:submit(ser);'. Looking at xsltforms.js, the line in XsltForms_submission.prototype.submit that invokes JS is this one: eval("ser = (" + action.substr(11) + ");"); So my work-around is to make the garbage appended to the action harmless by making it a comment: <xf:submission id='submit' method='get' relevant='true' replace='instance' serialization='application/xml' action='javascript:submit(ser));//' /> The line of JS eval'd might be something like: ser = (submit(ser));//?var1=val1&var2=val2... Would it be OK to change the code so it never appends URL-encoded instance data to an action that starts with 'javascript:' ? Also, can XSLTForms co-exist with jQuery now? Currently I put my forms into iframes, which is mostly OK, but it would be nice in future to have everything in one integrated page. Thanks very much! /A |
From: Alain C. <ala...@ag...> - 2013-03-25 21:15:45
|
Hi Adam, > Looking at xsltforms.js, the line in > XsltForms_submission.prototype.submit that invokes JS is this one: > > eval("ser = (" + action.substr(11) + ");"); > > So my work-around is to make the garbage appended to the action > harmless by making it a comment: > > <xf:submission > id='submit' > method='get' > relevant='true' > replace='instance' > serialization='application/xml' > action='javascript:submit(ser));//' > /> > > The line of JS eval'd might be something like: > > ser = (submit(ser));//?var1=val1&var2=val2... By default, XSLTForms is serializing the current instance with a get method in the query string: if ((method === "get" || method === "delete") && this.serialization !== "none" && action.substr(0, 9) !== "opener://" && action.substr(0, 8) !== "local://") { var tourl = XsltForms_submission.toUrl_(node, this.separator); action += (action.indexOf('?') === -1? '?' : this.separator) + tourl.substr(0, tourl.length - this.separator.length); } The test condition could be extended for Javascript: && action.substr(0,11) !== "javascript:" Could you please test with this? > Also, can XSLTForms co-exist with jQuery now? Currently I put my > forms into iframes, which is mostly OK, but it would be nice in future > to have everything in one integrated page. > I think that some XSLTForms users have already mixed it with jQuery. Do you have a test case which doesn't work? Thanks! -Alain |
From: Adam M. <Ada...@gm...> - 2013-03-27 09:23:56
|
Hi Alain, > The test condition could be extended for Javascript: && action.substr(0,11) !== "javascript:" > Could you please test with this? I did try that code change and it fixes the problem for me. The work-around I use is OK, but it's still nicer to avoid such tricks of course. > I think that some XSLTForms users have already mixed it with jQuery. Do you have a test case which > doesn't work? It's been awhile since I tried to use jQuery with XSLTForms. I'm glad to hear they may co-exist now. I was only curious & probably won't try it for awhile. If I have trouble when I do try it, I'll share a test case with you of course. Thanks for your help! /Adam On Mon, Mar 25, 2013 at 3:15 PM, Alain Couthures <ala...@ag...> wrote: > Hi Adam, > >> Looking at xsltforms.js, the line in >> XsltForms_submission.prototype.submit that invokes JS is this one: >> >> eval("ser = (" + action.substr(11) + ");"); >> >> So my work-around is to make the garbage appended to the action >> harmless by making it a comment: >> >> <xf:submission >> id='submit' >> method='get' >> relevant='true' >> replace='instance' >> serialization='application/xml' >> action='javascript:submit(ser));//' >> /> >> >> The line of JS eval'd might be something like: >> >> ser = (submit(ser));//?var1=val1&var2=val2... > > By default, XSLTForms is serializing the current instance with a get method > in the query string: > > if ((method === "get" || method === "delete") && this.serialization > !== "none" && action.substr(0, 9) !== "opener://" && action.substr(0, 8) !== > "local://") { > var tourl = XsltForms_submission.toUrl_(node, this.separator); > action += (action.indexOf('?') === -1? '?' : this.separator) + > tourl.substr(0, tourl.length - this.separator.length); > } > > The test condition could be extended for Javascript: && action.substr(0,11) > !== "javascript:" > > Could you please test with this? > >> Also, can XSLTForms co-exist with jQuery now? Currently I put my >> forms into iframes, which is mostly OK, but it would be nice in future >> to have everything in one integrated page. >> > I think that some XSLTForms users have already mixed it with jQuery. Do you > have a test case which doesn't work? > > Thanks! > > -Alain |