Handling errors from scripts
If you prefer, you can handle user input errors from scripts with your own messages.
Change reformatOnFocusChange on the State Text part in the example in the previous section to false. Then add an event-to-script connection from the part's userInputConvertError event to the following script:
errorInState
CwMessagePrompter errorMessage: 'Please enter a valid USA state.'.
(self subpartNamed: 'StateText') setFocus.
where StateText is the name of your State text part.
Test your part.
Additionally, try removing the checkFailed to showErrorToUser connection of the Form Input Checker part. Then add an event-to-script connection from the checkFailed event of the Form Input Checker part to the following script:
errorInForm
| partInError |
partInError :=
(self subpartNamed: 'Form Input Checker1') errorView.
(partInError == (self subpartNamed: 'StateText')) ifTrue: [CwMessagePrompter errorMessage:
'Please enter a valid USA state name or abbreviation.'].
partInError setFocus.
The errorView attribute of the Form Input Checker part tells which part is in error.
Test your part again.
As you can see, you can mix and match any of the techniques described for validating user input to achieve the results you are looking for.
Last modified date: 01/29/2015