Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Color field validation not showing

default discord avatar
mng9391last year
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
    last year

    Hey

    @1050078247209140286

    sorry to hear you're having issues.

    @969226489549713438

    you mind jumping in here to help?

  • discord user avatar
    dribbens
    last year

    Hey

    @1050078247209140286

    . 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
    mng9391last year

    Hey

    @969226489549713438

    , 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
    last year

    I merged your PR, looked good. Thank you!

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.