Validator for ExtJS Checkbox

Very unfortunately ExtJS doesn’t offer a validator for its checkbox component.
Normally a validator checks whether a field is valid and takes care of displaying an error message if not. For a checkbox we would like that to happen if the checkbox is not selected.
Overriding the validate function of the checkbox we can provide such a functionality for all checkbox instances we are about to create:

The validator can be customized using the properties validateField and validateMessage.

Here’s a small code example:

Generic error handler for ExtJS

When you are doing client/server communication with ExtJS you probably run into the problem that you want to handle server side errors in a generic way.
A solution that I found is to override the handleFailure function in the Ext.data.Connection class:

This handler simply is called whenever a server side failure occurs. As the Connection class handles all communication this can happen also in Ext.Ajax or Ext.data.HttpProxy. In this example the error message to be displayed is retrieved from a server generated XML with the actual text being located at XPath Reason/Text.

So a server side error message might look like this: