Adding Custom Listeners to Panel Events

View panels can have custom event handlers that are automatically called when a specific user interface event occurs. There are three event types currently supported:

  • afterRefresh : the custom handler is called after the form field values are refreshed from the server during a call to Ab.form.Form.refresh() method (or during the showPanel command execution);
  • beforeSave : the custom event handler is called before the form field values are saved to the server during as call to Ab.form.Form.save() method (or during the saveForm command execution);
  • beforeDelete : the custom event handler is called before the form field values are saved to the server during as call to Ab.form.Form.deleteRecord() method (or during the deleteRecord command execution)


The custom event handlers are attached to the form panel as follows:

<panel type="form" id="wr_form"
afterRefresh="wr_form_afterRefresh"
beforeSave="wr_form_beforeSave"
beforeDelete="wr_form_beforeDelete">

File: \views\dashboards\staff\ab-dashboard-staff-request.axvw

When the event handlers are called, the Form object is passed as a parameter:

function wr_form_beforeSave( form ){
var fieldValues = form.getFieldValues();
...
}

File: \views\dashboards\staff\ab-dashboard-staff-request.js

The beforeSave and beforeDelete event handlers can perform custom form data validation. If the form data is not valid, they can:

  • Indicate problematic field or fields, that the form will highlight;
  • Add a custom error message, that the form will display;
  • Return false value to indicate that the operation (Save or Delete) cannot proceed.

function wr_form_beforeSave( form ){
...
if (getInputValue('wr.rm_id') == '') {
form.addInvalidField (
'wr.rm_id',
getMessage('error_rm_id'));
return false;
}
}

File: \views\dashboards\staff\ab-dashboard-staff-request.js

The Ab.form.Form.addInvalidField() can be called for more than one field – the form will highlight all indicated fields.

The event handler can return true or no value at all to allow the operation.