Re: [Xsltforms-support] Calling Javascript-defined functions from XForms.
Brought to you by:
alain-couthures
|
From: Franclin F. <f.f...@4c...> - 2010-01-22 13:02:13
|
On 21/01/10 21:34, COUTHURES Alain wrote:
> 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
Hi Alan,
Thanks for your reply.
Regarding point 1- I obviously tried to call the concat function to
dynamically work out the URL of the resource but it did not work. Here
is a pseudo-code:
<xf:trigger>
<xf:label>Call Js Function</xf:label>
<xf:load value=concat('javascript:',link/@url) ev:event="DOMActivate" />
</xf:trigger>
The model is:
<xf:model>
<xf:instance>
<data xmlns="">
<link id="lnk" url="testJS()"/>
<newlink/>
</data>
</xf:instance>
</xf:model>
Finally you said at the end of your mail that it is possible to define
your own XPath function with JavaScript with XSLTForms. Do you have any
example showing how thing can be achieved?
Waiting for your reply.
Regards,
Franclin.
|