validate "required"
keeganstothert opened this issue · 2 comments
I see the past issues around validate onSubmit and I would like to give a +1 for that feature. react-select v2 does not support the required prop so ideally we could get around that with a validator like validate: value => !!value
bring on the breaking changes!
I've faced a similar difficulty and wrote about my workaround
See #56 (comment)
Hi @keeganstothert!
bring on the breaking changes!
😄
does not support the required prop so ideally we could get around that with a validator like validate: value => !!value
I think is might be a great use case for the validate
method. I'm not quit sure if there's a need to introduce an additional method to validate the requirement of an input.
Have you considered separating your validators and re-composing? For example, you can have a isRequired
function solely for this purpose.
compose = (...fns) => /* compose implementation */;
const isRequired = value => !!value;
const isEmail = value => EMAIL_REGEX.test(value)
<input
{...text({
name: 'email',
validate: compose(isRequired, isEmail),
})}
/>
That said, I'll keep this in mind for future releases.