Re: [Xsltforms-support] Calling Javascript-defined functions from XForms.
Brought to you by:
alain-couthures
From: COUTHURES A. <ala...@ag...> - 2010-01-21 21:33:58
|
Hi Franclin, > I am trying to call a javascript function from XForms but to no avail. > Here is the issue : *How to pass some parameters to a Javascript > function from XForms?* > Let us consider the following JS function: > /function myfunction(par1, par2){ > alert('You have entered' + par1 + par2 ); > //Display a Google Map by passing par1 to it. > }/ > Parameters par1 and par2 will be the result of an XPath expression > computed by XForms. Ideally, it would be called from XForms like this: > /<xf:trigger> > <xf:load ref="link that contain the javascript function myfunction" > ev:event="DOMActivate"> > </xf:trigger>/ > > As far as I know (I may be wrong, though), the only way to call JS > functions from XForms is by using the load method and call the JS > function as an external resource. > This topics has already been touched on in an article in IBM's > DeveloperWorks that is located here: > /http://www.ibm.com/developerworks/xml/library/x-xformstipcalljs/index.html/ > The bottom line is that no parameter is passed to the function which > is thus not of great help in my case. > This problem has also been touched on here > /http://wiki.orbeon.com/forms/projects/client-side-api-for-custom-javascript-widgets/ > but again it is not implemented. > So here are my questions: > 1 - How to pass some parameters to a JS method from XForms? Instead of @ref, the ressource sub element can be used to generate the uri with an XPath expression so parameters can be passed using the XPath concat() function. > 2 - Is this feature implemented in XSLTForms? Yes, it is implemented in XSLTForms. > Finally it might be interesting to point that when I try to specify > the name of the JS method directly in the ref attribute of the load > element, XSLTForms raises an exception by saying that "*Function > http://www.w3.org/2005/xpath-functions myfunction() not found*" which > makes me think that XSLTForms considers the JS function as an XPath > function. How to tell XSLTForms that it is actually a JS function? With XSLTForms, it's also possible to define its own XPath functions with Javascript. There is just a specific template to respect about parameters and return value. -Alain |