Using the information here: https://docs.espocrm.com/development...rror-handlers/
In my system, users need to create entities called Sessions that are based on client availability. The beforeSave hook processes complex business rules to determine availablity, and then throws an error if the client is not avaiable. Using a saveErrorHandler, I give the user an option to save anyway, which mostly works.
However, if the user decides to save the record, the page ends up in a weird state that is not quite edit mode and not quite detail mode. I don't know how to handle a successful save and the documentation does not give any information about this situation at all.
This is what happens when the user clicks "Save Anyway" in a modal after being informed about the availability problem:

The record is successfully saved and most of the fields are put into read-only mode, but the "Cancel" button is still visible and the URL still shows /create. Normally the URL would be something like .../#Session/view/<id> after creating or saving a record. Here is my error handler with the irrelevant parts removed:
Notably, the X-Skip-Availability header is the only way I have figured out how to pass data to the backend. Setting data.options does not work and neither does anything else I've tried. Here is how the backend uses the header:
In my system, users need to create entities called Sessions that are based on client availability. The beforeSave hook processes complex business rules to determine availablity, and then throws an error if the client is not avaiable. Using a saveErrorHandler, I give the user an option to save anyway, which mostly works.
However, if the user decides to save the record, the page ends up in a weird state that is not quite edit mode and not quite detail mode. I don't know how to handle a successful save and the documentation does not give any information about this situation at all.
This is what happens when the user clicks "Save Anyway" in a modal after being informed about the availability problem:
The record is successfully saved and most of the fields are put into read-only mode, but the "Cancel" button is still visible and the URL still shows /create. Normally the URL would be something like .../#Session/view/<id> after creating or saving a record. Here is my error handler with the irrelevant parts removed:
Code:
define('custom:error-handlers/client-unavailable', [], function () {
return class {
constructor(view) {
this.view = view;
}
process(data) {
...
this.view.createView('dialog', 'views/modal', {
...
buttonList: [
{
...
onClick: dialog => {
dialog.close();
return this.view.save({
headers: {'X-Skip-Availability': 'true'}
}).then(() => {
this.view.actionCancelEdit();
this.view.reRender();
});
}
},
...
});
PHP Code:
$headers = getallheaders();\
$skipAvailability = filter_var(
$headers['X-Skip-Availability'] ?? false,
FILTER_VALIDATE_BOOLEAN
);
