Trigger Validation

System Information
  • Strapi Version: 3.6.8
  • Operating System: macos
  • Database:
  • Node Version: 14.17.5
  • NPM Version:
  • Yarn Version: 1.22.11

Hello. Im currently working on Publish schedule based on docs. The problem i have is that i need to validate if all of required fields are filled.

I currenly added a Button in Header buttons (near Publish, save etc) “Schedule Publish” which correctly set publish_at_date in my article model.

How to run validation for My article model when user Click on This button?

i tried to use methods defined in useContentManagerEditViewDataManager
triggerFormValidation and checkFormErrors but those are not working or i use them wrongly.

Care to share your code for others to see what you did and how?

import { errors } from “@strapi/utils”;
import { CollectionStatus } from “…/…/…/…/vars”;
const { ApplicationError, NotFoundError } = errors;

export default {
async beforeCreate(event) {
//todo add validation before create for mandatory field
},
async beforeDelete(event) {
const { params } = event;
const entry = await strapi.entityService.findOne(
“api::csdd-one-sim-parameter-td-authorization.csdd-one-sim-parameter-td-authorization”,
params.where.id,
{}
);

if (!entry) {
  //handle if already deleted
  throw new NotFoundError(
    `Entry ID: ${params.where.id} not found / already deleted!`
  );
} else if (entry.status === CollectionStatus.SUBMITTED) {
  throw new ApplicationError(
    `Entry with status: ${CollectionStatus.SUBMITTED} cannot be deleted!`,
    {}
  );
}

},
};

i got same problem, here’s my code i want trigger form validation on lifecycle before create how to do it?

lifecycle happen to late to stop it aka if you where to stop it from updating in a lifecycle all components would still update. Only fix to this to my knowledge is a entity service decorator who are not documented.