AJAX events define an interaction sequence between a client and the server.
Typically, javascript will trigger the AJAX event which executes code and updates a region on the page.
For example, ticking a box might send data to the server, and depending on it's value, show or hide additional content on the page.
Any javascript event on an Oncord control can trigger an ajax event.
Just specify the native event name, suffixed by ajax.
For instance: onclickajax="..." and onchangeajax="...".
Attributes
- `id`
string
Give this control a unique id. Can be accessed in the client DOM (eg, document.getElementById('myid') or in the server DOM using [? $myid ?] or [? $('myid') ?]).
- `onSuccess`
string
JavaScript run when the ajax request completes, even if the servercommand threw; check rendered state before advancing a flow.
- `onSuccessCloseDialog`
int
Closes the dialog box on the client
- `onSuccessToastMessage`
string
The toast message to be displayed upon successful server command
- `onTrigger`
string
JavaScript to be executed when ajax event is triggered
- `showLoading`
bool
Whether to show a loading message. Default = true.
- `showLoadingMessage`
string
The text to display inside the loading message
- `updateRegions`
string|array
Sets which ajax:region controls to refresh
Examples
Checkbox Show / Hide
Shows or hides a block of content based on a checkbox.
HTML:
<p>Tick the box below to see a block show or hide.</p>
<ajax:event id="showhide_checkbox_ajaxevent" updateregions="showhide_ajaxregion" />
<forms:form>
<forms:row label="Tick this box...">
<forms:checkbox id="showhide_checkbox" onclickajax="showhide_checkbox_ajaxevent" label="Click for More Options" />
</forms:row>
<ajax:region id="showhide_ajaxregion">
<logic:if test="$showhide_checkbox.checked">
<forms:row label="And then these options show...">
<forms:editbox id="moreoptions" />
</forms:row>
</logic:if>
</ajax:region>
<forms:row type="one_column">
<forms:submitbutton>Submit Enquiry</forms:submitbutton>
</forms:row>
</forms:form>