Custom validation
Last updated
Was this helpful?
Last updated
Was this helpful?
A task may enforce custom validation for options by including validation logic in its code, inspecting the current value of an option and rendering an if the option does not meet its criteria.
A modification to a task option will always result in a new being rendered. In this way, a task developer may provide the user with immediate feedback on their task configuration.
In this example, a task begins by validating an option called "A positive number". The only flags on this option are "required" and "number", meaning that Mechanic's involvement is limited to making sure the user fills in this task option with a number.
Once the option is filled in, the task preview will be rendered. If the user has entered a zero, or a negative number, the is used to generate an . The error message will then be shown to the user, and they will be prevented from saving the task until they provide valid input.