Adding a Gadget Callback
- Last UpdatedMar 10, 2023
- 2 minute read
To perform intelligent actions a form or gadget must invoke a callback. You now add a simple gadget callback to the hello form.
You add a second button, change message, which will execute a callback to modify the Message paragraph gadget.
layout form !!hello AutoAlign
paragraph .Message text 'Hello world'
button .change ‘Change message’ callback |!this.message.val = ‘Modified’|
button .bye 'Goodbye' OK
exit

A gadget callback is defined by the callback command followed by a command or PML function enclosed in text delimiters. As you are giving a text string as part of the command which is itself supplied as a text string, you have had to use two kinds of delimiter: the apostrophe, (') and the (|) vertical bar.
Note:
The use of This to mean the current form. When the callback is executed, the command will set the
value member of the gadget Message on this form to read Modified rather than Hello world.
!this.message.val = 'Modified'
Note:
The gadget callback could have been the following, to change the value of a paragraph
gadget on another form named !!OtherForm.
|!!OtherForm.Para.val = 'Modified'|
Typically, a callback will involve many commands and could be a complex piece of code in its own right. In practice, the recommended way of defining a complicated callback is to use a form method.
First though, you need to store our form definition in a file so that they can edit it.