Ignition perspective Limit number of characters allowed in input text field

how to limit number of characters allowed in input text field and text area in ignition perspective

1 Like

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]
  1. Create the custom property altMax
  2. Turn off deferUpdates
  3. Turn off rejectUpdatesWhileFocused
  4. 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.

1 Like

TIL. I assumed slicing would throw an IndexOutOfBoundsException if self.custom.altMax was too big. Thanks for the simplification.

1 Like

Thanks the simple solution. It work well

1 Like

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.