Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Using .required('This field is required') is cleaner than invalidating… #461

Closed
wants to merge 5 commits into from
Closed

Conversation

nightness
Copy link

@nightness nightness commented Jan 11, 2021

This change allows .phone() to validate true for empty values so that .required can explain it's a required field. Examples...

Required

    phone: Yup
        .string()
        .required('Phone number is a required field')
        .phone('US', true, 'Phone number is not valid'),

Not Required

    phone: Yup
        .string()
        .phone('US', true, 'Phone number is not valid'),

Closes #313

@abhisekp abhisekp self-requested a review January 19, 2021 19:53
src/yup-phone.ts Outdated Show resolved Hide resolved
@abhisekp
Copy link
Owner

abhisekp commented Mar 9, 2021

Hi @JulienRst Can you please review this and make sure that this is backward compatible or new major release is needed.

Co-authored-by: Abhisek Pattnaik <[email protected]>
@nightness
Copy link
Author

nightness commented Mar 9, 2021

@abhisekp I suggest a new major release, as the change would allow empty phone number submits if the developer didn't explicitly define an .isRequired and is relying on the existing behavior to prevent empty phone numbers.

@nightness
Copy link
Author

@abhisekp I'm unsure how to proceed with the failed checks; they don't involve changes I made

@abhisekp
Copy link
Owner

abhisekp commented May 3, 2021

@nightness Sorry for the delay. Will look into this and make a major release.

1 similar comment
@abhisekp
Copy link
Owner

abhisekp commented May 3, 2021

@nightness Sorry for the delay. Will look into this and make a major release.

@sebastiansson
Copy link

This needs to be merged, all the default fields (like email) accept empty strings when not using .required(). This should work likewise.

@jbcrestot
Copy link

@abhisekp if you allow me to contribute, I can try to fix the branch

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

notRequired() with empty string causes validation to fail
4 participants