Setting data types from scripts
If you want to control exactly when user input is checked, you can write a script that can associate a data type with a part at any given time.
Try creating a new visual part similar to the one in the previous example. For this example, just create one State Text part and one OK push button and leave the data type of the State Text part at the default (none).
Then add two event-to-action connections:
•Connect the openedWidget event of the window to the setFocus action of StateText.
•Connect the clicked event of the OK push button to the script below.
checkForm
| dataType string |
dataType := AbtUSAStateConverter new.
string := (self subpartNamed: 'StateText') string.
dataType displayToObject: string ifError: :err |
CwMessagePrompter errorMessage: 'Please enter a valid USA state.'.
(self subpartNamed: 'StateText') setFocus].
Even though no data type was set for the Text part, when the script runs, it creates a USA State data type and checks for a valid state by sending the user input string the displayToObject:ifError: message. If the check fails, the statements inside the error block are run.
Note:
When you pass an error block as an argument in a message, you must declare a temporary variable inside the block. That is why :err is declared, even though it is not used in any statements inside the block.
Last modified date: 01/29/2015