Re: [Xsltforms-support] Calling Javascript-defined functions from XForms.
Brought to you by:
alain-couthures
|
From: Cyril <sfg...@fr...> - 2015-06-20 07:24:20
|
Hello, I'm trying to use the load element with a javascript function, to do things like changing the page title or the anchor dynamically, and there's some strange problems. I managed to do it with the setvalue element though, but I don't know if it's a correct way to do it with xforms or if it's just working with Xsltforms. Here is the code : > <?xml version="1.0" encoding="UTF-8"?> > <?xml-stylesheet href="xsltforms/xsltforms.xsl" type="text/xsl"?> > <html > xmlns="http://www.w3.org/1999/xhtml" > xmlns:xf="http://www.w3.org/2002/xforms" > xmlns:xsd="http://www.w3.org/2001/XMLSchema" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xmlns:ev="http://www.w3.org/2001/xml-events" > xmlns:js="javascript:code"> > <head> > <title>Test News</title> > <script type="text/javascript"> > function intMyAlert(str) { > alert(str); > return 1; > } > </script> > <xf:model id="mdlMyModel"> > > <xf:instance id="itcMyInstance"> > <data xmlns=""> > <text>My Instance Text</text> > <dump/> > </data> > </xf:instance> > </xf:model> > </head> > <body> > <h3>Load Javascript Test</h3> > <div> > <p>Test 1 : > <xf:trigger> > <xf:label>Alert()</xf:label> > <xf:action ev:event="DOMActivate"> > <xf:load resource="javascript:alert('Hello > World !')" /> > </xf:action> > </xf:trigger> > </p> > > <p>Test 2 : > <xf:trigger> > <xf:label>Alert() + namespace 'js'</xf:label> > <xf:action ev:event="DOMActivate"> > <xf:load resource="js:alert('Hello World !')" /> > </xf:action> > </xf:trigger> > </p> > > <p>Test 3 : > <xf:trigger> > <xf:label>Alert() + resource value</xf:label> > <xf:action ev:event="DOMActivate"> > <xf:load> > <xf:resource value="js:alert('Hello World > !')"/> > </xf:load> > </xf:action> > </xf:trigger> > </p> > > <p>Test 4 : > <xf:trigger> > <xf:label>Alert() + instance text</xf:label> > <xf:action ev:event="DOMActivate"> > <xf:load > resource="javascript:alert(instance('itcMyInstance')/text)" /> > </xf:action> > </xf:trigger> > </p> > > <p/> > <h3>Setvalue Javascript Test</h3> > <xf:trigger> > <xf:label>Function + instance text + setvalue</xf:label> > <xf:action ev:event="DOMActivate"> > <xf:setvalue ref="instance('itcMyInstance')/dump" > value="js:intMyAlert(instance('itcMyInstance')/text)"/> > </xf:action> > </xf:trigger> > </div> > </body> > </html> With Test 2 in think the new namespace for javascript is not recognized and Test 3 load the script but then tries to load the page « Hello World ! ». With Test 4 there's a XSLTForms Exception : « instance is not defined ». Regards, Cyril. |