Validating Input to Text Fields
- Last UpdatedOct 30, 2024
- 1 minute read
The text field gadget has an optional validation callback member which you can specify:
!textfield.ValidateCall = <callback string>
When a text input field is actioned (by modifying it and Tabbing away, or pressing ENTER, or when a button on the form is pressed or the form's OKcall is executed), it is automatically checked to make sure that the typed-in value matches the field's TYPE and its FORMAT constraints. If so, then your VALIDATECALL is actioned.
The VALIDATECALL is used to apply any checks you want. If an error is encountered then the callback raises the error and returns.
Note:
The validation callback must not attempt to change the value of the text field. It
should just detect and raise an error.
When an error is raised, an error alert is displayed and the text field is left with keyboard focus and error highlight. No further form or gadget callbacks are executed and the form is not dismissed from the screen. You can then modify the field and re-action it.
The VALIDATECALL is a standard callback, and so it can be a single command, a PML function, method or macro, or an open PML method or function. For an open callback, for example:
!textField.validateCall = '!this.textvalidate('
the corresponding method must be:
define method .1textvalidate( !textin is GADGET, !action is STRING )
where the action string will be 'VALIDATE'.