Hi Franclin,
I’ve always successfully called my javascript functions with:
<xforms:action ev:event=”myevent”>
<xxforms:script>
myJavascriptFunction();
</xxforms:script>
</xforms:action>
I’m not sure exactly how to get parameters other than using (this)
when referencing the caller object itself, so hopefully someone else can help
you there, but you can always save the parameters they selected to an instance
(bound to a hidden output field) and then get the values of that instance with “ORBEON.xforms.Document.getValue()”
inside the javascript function.
Good luck!
Stephanie
From: Franclin Foping
[mailto:[hidden email]]
Sent: Wednesday, January 20, 2010 11:53 AM
To: [hidden email]
Subject: [ops-users] Calling Javascript-defined functions from XForms.
Hi All,
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?
2 - Is this feature 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?
In order to reproduce this case I did this:
<xf:load ref=<a
href="javascript:myfunction(number(par1),string(par2))">"javascript:myfunction(number(par1),string(par2))"
ev:event="DOMActivate"/>
I am anxiously waiting for your reply.
Regards,
Franclin.
Free forum by Nabble | Edit this page |