Re: [Xsltforms-support] Asynchronous javascript.
Brought to you by:
alain-couthures
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. > |