6. More About Events and Actions
Editable ListBox
<< Previous   |   Back to Main   |   Conditional Events >>

View Source
will open in a new window
Combining Multiple Actions on Events
We can combine mulitple actions together for events, and we can also use the same set of actions for on multiple events or controls.

In this example, we have a listbox, and we allow the user to dynamically add items to that listbox. On submitting, we want to perform the following actions:
  • Disable the Listbox (via Javascript)
  • Disable the Textbox (via Javascript)
  • Disable the Button (via Javascript)
  • Make an AJAX call to the PHP method AddListItem
The PHP method AddListItem will then proceed to add the item into the listbox, and re-enable all the controls that were disabled.

Note that what we are doing is combining multiple actions together into an action array (e.g. QAction[]). Also note that this action array is defined on two different controls: the button (as a QClickEvent) and the textbox (as a QEnterKeyEvent).

Also note that we also add a QTerminateAction action to the textbox in response to the QEnterKeyEvent. The reason for this is that on some browsers, hitting the enter key in a textbox would cause the form to do a traditional form.submit() call. Given the way Qforms operates with named actions, and especially given the fact that this Qform is using AJAX-based actions, we do not want the browser to be haphazardly performing submits.

Finally, while this example uses QAjaxAction to make that an AJAX-based call to the PHP AddListItem method, note that this example can just as easily have made the call to AddListItem via a standard QServerAction. The concept of combining multiple actions together and the concept of reusing an array of actions on different controls/events remain the same.






<none>