SimeonGriggs/sanity-quick-fields

Feature Request: Validation

Closed this issue ยท 5 comments

ppo commented

First, thanks for this plugins ๐Ÿ˜€

As you haven't implemented validation, is there a catch? If not, please, this would be very useful!

And even better if you can provide an easier way to configure basic common things like require, min/max, regex, error/warning messages ๐Ÿ˜

For example: qF(name, type, options, validation)

validation can be a function, that is passed as is:

Rule => Rule.required().max(50).error('Required and max 50 chars.')
Rule => [
  Rule.required().max(50).error('Required and max 50 chars.'),
  Rule.regex(/^[-a-z0-9]+$/g).error('Only a-z, 0-9, and -.'),
  Rule.min(10).warning('Should be at least 10 chars')
]

validation can be an object:

{ error: 'Required and max 50 chars.', required: true, max: 50 }

validation can be an array:

[
  { error: 'Required and max 50 chars.', required: true, max: 50 },
  { error: 'Only a-z, 0-9, and -.', regex: /^[-a-z0-9]+$/g },
  { warning: 'Should be at least 10 chars', min: 10 }
]
ppo commented

Quick workaround:

const qFv = (f, validation) => ({ ...f, validation });

qFv(qF('title'), Rule => Rule.required()),

Hey! Great work. I don't really use this library anymore myself but I love that you've done a PR (#2) for the feature, so I'm gonna go merge it!

ppo commented

Thanks. Are you using something else? Or just the plain verbose syntax? ๐Ÿคทโ€โ™‚๏ธ

Hey! Great work. I don't really use this library anymore myself but I love that you've done a PR (#2) for the feature, so I'm gonna go merge it!

Is it still supported? I was about to open an issue related to qF breaking the sanity graphql deploy command. ๐Ÿ˜…

Open away @sandren! I'd still like this library to work even if I'm not still personally using it ๐Ÿ˜