Is it possible to use Local API in the field validate function?
If I manually import payload, it will be undefined.
You should have access to
payload
in your validate function without having to import it.
validate: async (value, { payload }) => {
const getSomething = await payload.find({ /** whatever you need */});
}
Does this help?
I have tried it this way, but the outcome is the same:
"Cannot read properties of undefined (reading "find")"
This is the code I tried just now:
validate: async (value, {payload}) => {
const getSomething = await payload.find({
collection: 'pages'
});
console.log(getSomething);
},
I don't think this is true, bc validate is used on the frontend so it would not have access to the payload class
So no, you will not be able to use payload in the validate function.You could instead use a beforeValidate hook and access payload there and throw an error if you need.
Star
Discord
online
Get dedicated engineering support directly from the Payload team.