I'm using the color field from
https://github.com/payloadcms/custom-field-guide, but when I set it as required, the validation doesn't appear.
Hey @mng9391 sorry to hear you're having issues. @dribbens you mind jumping in here to help?
Hey @mng9391. The thing to note custom field validation functions is that they override the payload field default validation methods. If you want call the defaults the recommended way is to import from 'payload' the field validation for the type that best fits your custom field and return that call instead of the result you would normally return. Does that make sense?
Alternatively you can always just copy the validation required logic from the text function which normally looks like this:
if (required) {
if (typeof value !== 'string' || value?.length === 0) {
return t('validation:required')
}
}
Hey @dribbens , I noticed that the 'Input' component for the color field doesn't handle errors. I've already addressed this issue and have submitted a PR to fix it. You can review the changes here:
https://github.com/payloadcms/custom-field-guide/pull/5I merged your PR, looked good. Thank you!
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.