Color field validation not showing

default discord avatar
mng9391
2 months ago
4

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.

  • discord user avatar
    seanzubrickas
    Payload Team
    2 months ago

    Hey @mng9391 sorry to hear you're having issues. @dribbens you mind jumping in here to help?

  • discord user avatar
    dribbens
    Payload Team
    2 months ago

    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')
        }
      }
  • default discord avatar
    mng9391
    2 months ago

    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/5
  • discord user avatar
    dribbens
    Payload Team
    2 months ago

    I merged your PR, looked good. Thank you!

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.