how to limit number of characters allowed in input text field and text area in ignition perspective
This might help.
This script is modified from what @pturmel wrote in the linked thread.
tf = self
if tf.custom.altMax > 1:
if len(currentValue.value) > tf.custom.altMax:
tf.props.text = tf.props.text[:tf.custom.altMax]
- Create the custom property altMax
- Turn off deferUpdates
- Turn off rejectUpdatesWhileFocused
- Put this in a property change script on the text property of text property on your text field.
That can even be simplified a bit. The full ChangeScript can just be one line:
self.props.text = self.props.text[:self.custom.altMax]
There’s no need for a length check.
TIL. I assumed slicing would throw an IndexOutOfBoundsException if self.custom.altMax was too big. Thanks for the simplification.
Thanks the simple solution. It work well
can you elaborate on how to limit my text box input to 17 character I am not sure where to find this on the manual for more explanation I would really appreciate it. FYI my tag is a string character
To follow the example that @zacht posted.
create a custom property on the component named altMax
set deferUpdates
and rejectUpdatesWhileFocused
to false
Righ click the text property, and then select Add Change Script...
Insert the script as @cmallonee posted (be sure to indent it correctly), click okay and you’re done.
I get a ‘NoneType’ object is unsubscriptable
Going to need more information to help. What does your code look like?
it had a binding that was messing it up