Wednesday, 27 June 2012

Strip out commas and full stops from an input box in xform

To normalize data entered by user, e.g. strip out commas and full stops from an input box in xform, no matter how many commas / full stops are added in the end:

<xforms:input ref="xx">
      <xforms:label>label</xforms:label>
          <xforms:action ev:event="xforms-value-changed">
                  <xforms:setvalue ref=".[substring(.,string-length(.))='.']"
                                               value="substring(.,1,string-length(.)-1)"/>
                  <xforms:setvalue ref=".[substring(.,string-length(.))=',']"
                                               value="substring(.,1,string-length(.)-1)"/>
          </xforms:action>
</xforms:input>

NB: if you want to replace the value by a fixed string, it must be in a pair of single quotes, e.g.
<xforms:setvalue ref=".[substring(.,string-length(.))=',']"
                             value="'NEW TEXT'"/>

No comments:

Post a Comment