Custom Validation
Some input widgets have built-in validation (e.g., EmailInput
, NumberInput
). However, you can also implement custom validation logic by setting the error
property.
from abstra.forms import TextInput, run
def email_validation_page(state):
email_input = TextInput("Email", key="email")
if state.get("email") == "some@spam.com":
email_input.errors = "We don't allow spam emails!"
# Or
# email_input.errors = ["We don't allow spam emails!", "Please use a different email."]
return [email_input]
run([email_validation_page])
info
- Assign an error message to
error
for custom validation feedback. - The error message will be displayed below the input field.