Re: How to change xforms model via Javascript?

Posted by Ryan Puddephatt on
URL: https://discuss.orbeon.com/How-to-change-xforms-model-via-Javascript-tp33221p33223.html

Martin,
    The code you have included won't work with Orbeon, one reason why it isn't implemented is this is a possible security risk in cases where not all the instance data is shown to the user.

Orbeon do have some extention functions within their JavaScript API, goto http://www.orbeon.com/ops/doc/reference-xforms-ng#xforms-javascript of the Orbeon documentation, this may well cover what you need

You can change the value of an input on screen, but not an xpath in the instance. The rebuild and refresh should be done automatically, but you would need to create a external events (also in the documentation) or a hidden trigger to force this.

Hope this helps

Ryan

Ryan Puddephatt
Software Engineer
 
Teleflex Group - IT UK
1 Michaelson Square
Livingston
West Lothian
Scotland
EH54 7DP
 
e> [hidden email]
t> +44(0)1506 407 110
f> +44(0)1506 407 108
w> www.teleflex.com



[hidden email] wrote:
Hello guys,

I found the following snippet, to change a value in the xforms model
via Javascript. This is conform to W3C spec, I think. Unfortunately,
this does not work with Orbeon.

In the post http://mail-archive.objectweb.org/ops-users/2006-06/msg00043.html Alex says, that DOM access via Javascript is currently not implemented.

My use case is that I would like to get the remote ip from the client machine -
usually server-side accessed via "request.getRemoteHost();". The problem is in XForms I do not have the request object anymore. So I tried to include a JSP
page within the xform. There is a hidden field with the hostname. This works fine. Now, I want to copy the value to the xforms model. But do not have any idea how this can be done with your implementation. 

Is there any possibility to write to the model via Javascript? I am using Intalio BPMS and the xform is a workflow task. The form output goes back to my business process. So I am a bit restricted and I would like to do it directly within the XHTML page.

Cheers,
Martin.

Snippet:

<html xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:xforms="http://www.w3.org/2002/xforms" 
      xmlns:event="http://www.w3.org/2001/xml-events">
<head>
  <script language="javascript"> 
    function changeMe(){
      var model = document.getElementById("myModel");
      var instance = model.getInstanceDocument ("myInstance");
      var textElements = instance.getElementsByTagName("text");
      textElements[0].firstChild.nodeValue = 'Changed!';
      model.rebuild();
      model.refresh();
     }
  </script>
  <xforms:model id="myModel"> 
    <xforms:instance id="myInstance">
      <text xmlns="">Change Me!</text>
    </xforms:instance>
    <xforms:instance id="script"> 
      <script url=<a class="moz-txt-link-rfc2396E" href="javascript:changeMe()">"javascript:changeMe()"/>
    </xforms:instance>
  </xforms:model>
</head>
<body> 
  <xforms:input ref="/text"/>
  <xforms:trigger>
    <xforms:label>Change!</xforms:label>
    <xforms:load resource=<a class="moz-txt-link-rfc2396E" href="javascript:changeMe()">"javascript:changeMe()" event:event="DOMActivate"/>
  </xforms:trigger>
</body>
</html>

  

-- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: [hidden email] For general help: [hidden email] ObjectWeb mailing lists service home page: http://www.objectweb.org/wws


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws