I cant use the Numeric Entry Field because what I want is let the user to insert their contact number so Numeric Entry Field is not the option for me. You get it what I means ? Therefore, what should I do in order to format the text field that only accept numbers. For instance, 01589652586.
There’s no way to prevent a user from entering characters in a Text Field. You can prevent string characters from being placed into the value with smart logic in a value change script, but again, that won’t prevent a user from putting characters into the Text Field. So using this route you’ll encounter a difference between what is displayed and what the true value is until focus is lost, at which point the component will display the true value.
User is able to supply invalid characters, but the change script is writing the last “valid” value to props.text whenever an invalid character is supplied:
There is no mechanism to ignore invalid characters or prevent them from being typed into the Text Field or Text Area components. All capturing, handling, and sanitizing is done on the back-end, through change scripts and binding rules you apply.
To enforce alpha values through the change script:
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
if currentValue and currentValue.value not in [None, ""]:
if not currentValue.value.isalpha()
self.props.text = previousValue.value
Now, as mentioned, this still executes after the user has supplied some text value, so they might have typed something like "alphab3tic", where the 3 should have been disallowed. One minor trick to prevent the field from showing "alphab3tic" due to the disallowed 3 character is to set TextField.props.deferUpdates AND TextField.props.rejectUpdatesWhileFocused to False. Doing so (with the same change script applied) will validate each character as it is typed, resulting in the 3 being ignored after it has been typed. As you are no longer rejecting updates while focused, the front-end session is displaying the sanitized value.