Search code examples
xmlxsltxpathorbeonxforms

Orbeon Form Builder: Define Calculated Value for InputField using XPath


I am using input fields in Orbeon Form Builder that should be filled with the text "null", when formdata will be sent as xml to service, if a user doesn't fill it in Form Runner. Suppose I have to define calculated value field with XPath expression. How can I do it? Because I don't want to have an empty element in result xml data file.


Solution

  • The simplest way to provide 'null' as a default value in XForms is to write 'null' as the value of the element or attribute in question in the document instance you load to begin with. If you want the elements shoesize and sockscolor to default to null, write your XForms instance accordingly:

    <xforms:instance id="main" xmlns="">
      <mydata>
        <name></name>
        <age></age>
        <shoesize>null</shoesize>
        <sockscolor>null</sockscolor>
      </mydata>
    </xforms:instance>
    

    If you load the document instance from an external document, you'll need to do something more complicated, like setting the values of shoesize and sockscolor on as part of the action when the user clicks the submit button. Something like:

    <xforms:trigger>
      <xforms:label>Submit</xforms:label>
      <xforms:action ev:event="DOMActivate">
        <xforms:setvalue ref="shoesize"
                         if=".=''"
                         value="'null'"/>
        <xforms:setvalue ref="sockscolor"
                         if=".=''"
                         value="'null'"/>
        <xforms:send submission="go"/>
      </xforms:action>
    </xforms:trigger>
    

    This is just generic XForms, though, and does not exploit any special features FormsRunner might have to make this easier.