0

Can i use a read-only xf:input act like xf:output in Orbeon? How to set the value of a readonly input field?

simpler code sample:

<xf:input ref="//Some/Elements/TotalCredit"
          value="round(($quantity) * ($creditPerUnit))">
</xf:input >

<xf:output ref="//Some/Elements/TotalCredit" 
           value="round(($quantity) * ($creditPerUnit))"/>

In the above code the xf:input shows only the initial value from the model! It doesn't update! But xf:output value is updated as expected! enter image description here

So, how can set xf:input's value like xf:output?

  • I don't want to use calculation in bind.
oikonomopo
  • 4,025
  • 7
  • 44
  • 73

2 Answers2

1

In your example, you have an xf:input with both a ref and a value; I am not sure what you expect this to do, or if that makes sense, but for sure it currently won't work:

  • With the xf:output, you can have both a ref and a value, where the node pointed by ref can influence whether the xf:output is shown and the value gives it its value.

  • If you want to do the same with an xf:input, it can put the result of your calculation in the ref (in your case round(($quantity) * ($creditPerUnit))). If that expression returns an atomic value, then the input field will be readonly, which I think should take care of your situation.

avernet
  • 30,895
  • 44
  • 126
  • 163
  • I know the one way of calculation in input's Bind, but in my situation i can't use this way, because the xf:input is inside xf:repeat, and not in it's nodeset! It refers to a node that is outside the repeated nodes.Can i pass to the calculation in Bind a variable from View? – oikonomopo Apr 02 '15 at 06:22
  • Yes, you should be able to use in the calculation for a field inside the repeat the value of a field outside of the repeat. If this is for a form you created with Form Builder, you can just refer to that value as `$control-name` in the calculation, where `control-name` would be the control name of that field outside of the repeat. – avernet Apr 07 '15 at 06:48
0

This is how i made it, considering this and this posts.

    //First Input
    <xf:input ref="//Some/Elements/PreviousInputCreditPerUnit">
      <xf:action ev:event="xforms-enabled xxforms-iteration-moved xforms-value-changed">
        <xf:setvalue 
          ref="//Some/Elements/ReadOnlyInputIK" 
          value="round(($quantity) * ($creditPerUnit))"/>
      </xf:action>
    </xf:input>

    //Second input
    <xf:input ref="//Some/Elements/PreviousInputQuantity">
      <xf:action ev:event="xforms-value-changed">
        <xf:setvalue 
          ref="//Some/Elements/ReadOnlyInputIK" 
          value="round(($quantity) * ($creditPerUnit))"/>
      </xf:action>
    </xf:input>

    //Third ReadOnly Input (acts like xf:output)
    <xf:input ref="//Some/Elements/ReadOnlyInput">
    </xf:input>

Note the action event in the first column of my repeated row:

ev:event="xforms-enabled xxforms-iteration-moved xforms-value-changed"

See this example from Orbeon.

Community
  • 1
  • 1
oikonomopo
  • 4,025
  • 7
  • 44
  • 73