Limit the number of input characters in TextArea
-
wrote on 18 May 2017, 13:51 last edited by
Hi,
How to limit the number of input characters in TextArea?
there is one feature in TextInput name maximumLength for that how about TextArea?Thanks,
-
There is nothing built-in, but you can implement the limit with something like this:
TextArea { onTextChanged: if (length > MyLimit) remove(MyLimit, length); }
-
There is nothing built-in, but you can implement the limit with something like this:
TextArea { onTextChanged: if (length > MyLimit) remove(MyLimit, length); }
-
:-) you're welcome, happy coding!
-
wrote on 8 May 2021, 10:58 last edited by
Indeed, I support using this way:
onTextChanged: {
remove((cursorPosition-(length-maxlen)),cursorPosition)
}
it can prevent user from inserting characters in the middle part of the text.
Howerer, when "ctrl + z" is typed, there're still problems. -
wrote on 25 Jun 2023, 13:21 last edited by mmjvox
I think this is better:
property int maximumLength: -1; property string lastValidText: ""; onTextChanged: { if (text.length > maximumLength && maximumLength>-1) { var currentPosition = cursorPosition-1; text = lastValidText; cursorPosition = currentPosition; } else { lastValidText = text; } }