Re: [Xsltforms-support] Setting node value in javascript
Brought to you by:
alain-couthures
From: Mark S. <m_s...@ma...> - 2012-07-15 11:51:00
|
Hi, I have noticed that if I change the form so that the js function is called from an XForms control using xf:load AND I add a bind to the model, then the XForms UI updates to reflect the value change caused by the js function. However, when the function is triggered elsewhere in the page, the UI is not updated, even with the bind statement in the model. Here is the updated form. Mark <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet href="../xsltforms/xsltforms.xsl" type="text/xsl"?> <?xsltforms-options debug="no"?> <?css-conversion no?> <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>Discover your Whithorn</title> <script type='text/javascript'> function onFeatureSelect(evt) { var modelElem = document.getElementById("theModel"); var instDoc = modelElem.getInstanceDocument("variables"); var xmlSite = instDoc.getElementsByTagName("currSite")[0]; xmlSite.childNodes[0].nodeValue = evt; //alert(xmlSite.childNodes[0].nodeValue); modelElem.rebuild(); modelElem.recalculate(); modelElem.revalidate(); modelElem.refresh(); } </script> <xf:model id="theModel"> <xf:instance id="variables" xmlns=""> <doc> <currSite>Cairn Buy</currSite> <b/> </doc> </xf:instance> <xf:bind calculate="instance('variables')/currSite" nodeset="instance('variables')/b"/> </xf:model> </head> <body> <h2>Sites</h2> <div> <p>Value of instance('variables')/currSite is: <strong><xf:output value="instance('variables')/currSite"/></strong></p> <xf:trigger> <xf:label>Change to Hole Stone</xf:label> <xf:load ev:event="DOMActivate" resource="javascript:onFeatureSelect('Hole Stone')"/> </xf:trigger> <xf:trigger> <xf:label>Change to Cairn Buy</xf:label> <xf:load ev:event="DOMActivate" resource="javascript:onFeatureSelect('Cairn Buy')"/> </xf:trigger> <p onclick="onFeatureSelect('Hole Stone')">Set value of instance('variables')/currSite to Hole Stone</p> <p onclick="onFeatureSelect('Cairn Buy')">Set value of instance('variables')/currSite to Cairn Buy</p> </div> </body> </html> |