Thread: [Xsltforms-support] Asynchronous javascript.
Brought to you by:
alain-couthures
From: Mark L. <tin...@gm...> - 2013-10-04 20:15:09
|
Hi, I'm looking into whether I can inject results from the relocation API into an <xf:instance/> I've added in a extension JS function to do the call like so: <script > XPathCoreFunctions['http://example.net/xforms/new-functions/ new-func'] = new XPathFunction( false, XPathFunction.DEFAULT_NONE, false, function() {{ return navigator.geolocation.getCurrentPosition(show_map); }} ); function show_map(position) {{ var latitude = position.coords.latitude; var longitude = position.coords.longitude; alert(position.coords.latitude+","+ position.coords.longitude); return "hello"; }}; </script> However, I don't get a return as the js calls a callback rather than waiting. Any ideas? Rgds, Mark Lawson. |
From: Alain C. <ala...@ag...> - 2013-10-05 16:04:20
|
Hello Mark, This can be performed with actions and events because XForms 2.0 allows to associate properties to events: <html xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:ev="http://www.w3.org/2001/xml-events"> <head> <title>Asynchronous Javascript function call</title> <xf:model id="modelid"> <xf:instance id="instanceid" xmlns=""> <data> <latitude/> <longitude/> </data> </xf:instance> <xf:load ev:event="xforms-ready" resource="javascript:asynch()"/> <xf:action ev:event="callbackevent"> <xf:setvalue ref="latitude" value="event('latitude')"/> <xf:setvalue ref="longitude" value="event('longitude')"/> </xf:action> </xf:model> <script type="text/javascript"> function asynch() { navigator.geolocation.getCurrentPosition(show_map); } function show_map(position) { XsltForms_xmlevents.dispatch(document.getElementById("modelid"), "callbackevent", null, null, null, null, { latitude: position.coords.latitude, longitude: position.coords.longitude }); } </script> </head> <body> <xf:output value="latitude"> <xf:label>Latitude: </xf:label> </xf:output> <br/> <xf:output value="longitude"> <xf:label>Longitude: </xf:label> </xf:output> </body> </html> and my current location is: Latitude: 44.837789 Longitude: -0.57918 Thank you for your feedbacks! -Alain > I'm looking into whether I can inject results from the relocation API into an <xf:instance/> > I've added in a extension JS function to do the call like so: > > <script > > XPathCoreFunctions['http://example.net/xforms/new-functions/ new-func'] = > new XPathFunction( > false, > XPathFunction.DEFAULT_NONE, > false, > function() {{ > return navigator.geolocation.getCurrentPosition(show_map); > }} > ); > function show_map(position) {{ > var latitude = position.coords.latitude; > var longitude = position.coords.longitude; > alert(position.coords.latitude+","+ position.coords.longitude); > return "hello"; > }}; > </script> > > However, I don't get a return as the js calls a callback rather than waiting. Any ideas? > > Rgds, > > Mark Lawson. > |
From: Isidro V. V. <jv...@gm...> - 2013-10-07 19:46:09
|
I am trying to run the example presented here (http://en.wikibooks.org/wiki/XSLTForms/XSLTForms_only_Extensions#User-Defined_Functions) but the browser complains about a syntax error and, when I open the console, I see the error message: ReferenceError: XPathCoreFunctions is not defined Is that example updated to the current xsltforms version orhas anyone tested it? Best regards Isidro |
From: Isidro V. V. <jv...@gm...> - 2013-10-07 22:28:08
|
Well, I think I found it myself. Looking inside xsltforms.js I found similar functions and it, apparently, does what we want XsltForms_xpathCoreFunctions['http://example.net/xforms/new-functions/ new-func'] = new XsltForms_xpathFunction( false, XsltForms_xpathFunction.DEFAULT_NONE, false, function() { return "NEW FUNC"; } ); On 10/07/2013 08:45 PM, Isidro Vila Verde wrote: > I am trying to run the example presented here > (http://en.wikibooks.org/wiki/XSLTForms/XSLTForms_only_Extensions#User-Defined_Functions) > but the browser complains about a syntax error and, when I open the > console, I see the error message: > > ReferenceError: XPathCoreFunctions is not defined > > Is that example updated to the current xsltforms version orhas anyone > tested it? > > Best regards > > Isidro > |
From: William V. <wve...@vi...> - 2013-10-08 13:37:01
|
In the recent releases you can also use javascript functions directly in your XPath expressions. Take a look to the example on this message: http://sourceforge.net/p/xsltforms/mailman/message/31428268/ Regards, - Bill De: Isidro Vila Verde [mailto:jv...@gm...] Enviado el: lunes, 7 de octubre de 2013 17:28 Para: xsl...@li... Asunto: Re: [Xsltforms-support] User defined functions example Well, I think I found it myself. Looking inside xsltforms.js I found similar functions and it, apparently, does what we want XsltForms_xpathCoreFunctions['http://example.net/xforms/new-functions/ new-func'] = new XsltForms_xpathFunction( false, XsltForms_xpathFunction.DEFAULT_NONE, false, function() { return "NEW FUNC"; } ); On 10/07/2013 08:45 PM, Isidro Vila Verde wrote: I am trying to run the example presented here (http://en.wikibooks.org/wiki/XSLTForms/XSLTForms_only_Extensions#User-Defined_Functions) but the browser complains about a syntax error and, when I open the console, I see the error message: ReferenceError: XPathCoreFunctions is not defined Is that example updated to the current xsltforms version or has anyone tested it? Best regards Isidro |