Max number of characters in textarea

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Max number of characters in textarea

r.pecori
This post was updated on .
Hi,

I was using Orbeon Forms 4.0.0.rc1.201302120214 PE with development licence and I am trying to limit the number of charachters allowed into a textarea.

Is there a way to do so in orbeon/xforms?

I tried to put the attribute maxlength in the <xf:textarea> tag in the source code but nothing changed.

thank you in advance
Jez
Reply | Threaded
Open this post in threaded view
|

Re: Max number of characters in textarea

Jez
Hi

Assuming you want to constrain the data contained within the field, rather than the display of the field, I would recommend having a look at a regular expression constraint on the data.

In Form Builder include a constraint in the validation properties of the control to be something like:

"matches(., '^.{1,20}$')"

(or include it in the underlying data bind).

This will allow the value to be between 1 and 20 characters, as defined by the . (period) character.
Reply | Threaded
Open this post in threaded view
|

Re: Max number of characters in textarea

r.pecori
I have solved inserting in the field Constraints of the textarea the following code:

string-length(.)<50

where 50 is the upperbound.

thankyou
Reply | Threaded
Open this post in threaded view
|

Re: Max number of characters in textarea

r.pecori
And if I would like to limit the number displayed in the text area?

not only setting a constraint but preventing the user to enter more charachters than allowed?

thank you
Reply | Threaded
Open this post in threaded view
|

Re: Max number of characters in textarea

Erik Bruchez
Administrator
You can add an `xxf:maxlength` attribute on `xf:textarea`. This translates to the HTML `maxlength` attribute. But not all browsers support it, see:

http://www.w3schools.com/tags/att_textarea_maxlength.asp

For older browsers, the alternative is to use some dirty JavaScript to prevent input.

-Erik