set limit number of possible characters in textedit

Aug 19, 2010 at 12:19pm

set limit number of possible characters in textedit

Is it possible to set a limit to the number of letters that can be entered in a textedit object? I would like to limit the max number to lets say 200 characters (spaces included) and show the number of remaining characters.

#51850
Aug 19, 2010 at 2:36pm

The answer to your question is of course: Yes.

But I’m sure you want more than that.

Here’s a quick hack using the readonly attribute. Edit: Modified to support backspace (ASCII 8) to enable changing text while maintaining character limit.

– Pasted Max Patch, click to expand. –
#186075
Aug 19, 2010 at 10:22pm

niiiice!

#186076
Aug 19, 2010 at 10:39pm

Unfortunately there are further special keys to take into account (such as enter/return) that are handled as entered characters in the above.

I’d favour a method where you count what’s in the box each time (as the below). It suffers from slightly odd trailing whitespace issues (due to textedit stripping them from the output), but otherwise it should work, whatever is typed in.

The other issue arising in the above patch is that once you reach the limit you can’t edit it any more.

The below also doesn’t have a count down (but it’s trivial – take the length away from the maximum – and you’ll need to store the output and check for a tab or return character to send to the final output, but again that’s fairly minor to add using zl reg or something…

A.

– Pasted Max Patch, click to expand. –
#186077

You must be logged in to reply to this topic.