Search code examples
orbeon

Orbeon Forms: Populate Hidden Field at xform-ready


I know we can populate a hidden control at the xforms-ready event:

<xf:action event="xforms-ready" type="javascript"> 
   var vProtocol = window.location.protocol;
   var vSystem;
   if (vProtocol == 'file:') { vSystem = 'Yes' } else  { vSystem = 'No' };      
   ORBEON.xforms.Document.setValue(ORBEON.fr.API.findControlsByName("SystemType")[0],vSystem); 
</xf:action>

When we use xPath to within a control to query the value in SystemType, then we get no value. However, if I make the SystemType control visible then it all works as expected.

So how can I have a hidden control, and still retrieve the value?

Many thanks in advance

PeteA


Solution

  • You can't change the value of a readonly or hidden control with JavaScript. This is because, on the web, JavaScript running in the browser can't be "trusted" in the sense that what can be done in JavaScript, a malicious user can also do. In general, you wouldn't want users to be able to change the value of readonly or hidden controls.

    If in your case this isn't a concern, you can use a regular field and hide it with CSS, for instance by adding xforms-hidden in Custom CSS classes. This way, the control will be visually hidden but still present on the page, which will allow you to set its value with JavaScript.

    Dialog in which to add the custom CSS class