strapi-plugin-navigation
strapi-plugin-navigation copied to clipboard
Lifecycle Hooks - Errors thrown are not shown in UI
I tried to implement custom validation for additionalFields but when i throw an Error on the lifecycle hook the Errors is not shown in strapi UI.
The user cannot save, but I'm not able to display an Error Message.
Background is that I want to validate my custom Fields, cause we need to option that Navigation Items can expire (Seasonal stuff like Easter, Super Bowl and so on)
Note: I tried various other Error Classes, but non was processed.
Code Example:
navigationCommonService.registerLifeCycleHook({
callback: async (event) => {
const { expiry_date, start_date } = event.params.data.additionalFields || {};
if (expiry_date && start_date) {
const expiryDate = new Date(expiry_date);
const startDate = new Date(start_date);
if (expiryDate <= startDate) {
throw new ApplicationError('Validation failed.');
}
}
},
contentTypeName: "navigation-item",
hookName: "beforeUpdate",
});
Hello @cmaerz-dn , the validation is not exposed as part of the codebase yet. After discussions with some users of our plugin during the Strapi Conf we've decided to consider exposing the method for overwriting the zod schemas. Not yet on the backlog, but soon.
@cmaerz-dn support added in v3.1.0