XForms/Limiting Length

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Motivation[edit | edit source]

You want to warn a user that an input control exceeds a specified length.

Method[edit | edit source]

We will use the XForms "action" element and conditionally display a message if the string-length is larger than 50 characters. The following action should be placed within the control.

<xf:action ev:event="xforms-value-changed" if="string-length(.) &gt; 50">
   <xf:message level="modal">maximum length is 50 characters</xf:message>

Example with Textarea[edit | edit source]

<xf:textarea ref="short-message" incremental="true">
      <xf:action ev:event="xforms-value-changed" if="string-length(.) &gt; 140">
         <xf:message level="modal">Maximum message length is 140 characters.</xf:message>
<xf:output ref="short-message"/>