Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix picker validation #168

Merged
merged 1 commit into from
Jun 24, 2020
Merged

Fix picker validation #168

merged 1 commit into from
Jun 24, 2020

Conversation

michaldudak
Copy link
Contributor

Modified the condition to run the onError handler within pickers so they don't remove validation errors coming from fields.
Extracted the error handler to a separate function to reduce repetition.

Modified the condition to run the onError handler within pickers
so they don't remove validation errors coming from fields

export function createErrorHandler(fieldError: unknown, fieldName: string, setFieldError: (field: string, message: string) => void) {
return (error : ReactNode) => {
if (error !== fieldError && error !== '') {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where the meaningful change is: I removed the && !fieldError from condition. In cases where there was a validation error coming from Formik, error is empty and fieldError has value. Then setFieldError would incorrectly fire and set the field error to undefined (effectively breaking the validation).

@luuksommers
Copy link

Awesome work, hopefully this will be merged soon.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants