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

feat: adds validateOnLoad #622

Closed
wants to merge 1 commit into from
Closed

feat: adds validateOnLoad #622

wants to merge 1 commit into from

Conversation

morgs32
Copy link
Contributor

@morgs32 morgs32 commented May 8, 2018

Resolves #288

@morgs32
Copy link
Contributor Author

morgs32 commented Jul 25, 2018

Hi @jaredpalmer can we discuss before I clean up conflicts?

It appears that the react team stands behind calling setState from componentDidMount:
https://reactjs.org/docs/react-component.html#componentdidmount

And it's not a valid eslint rule on latest react

And as for the user experience, if the validation is synchronous, "the user won’t see the intermediate state" (according to the first link).

If the validation is async, then presumably the validation logic implements some loading state UI. In which case it seems fitting that that loading UI would commence when the Form loads.

What do you think?

@morgs32
Copy link
Contributor Author

morgs32 commented Jul 31, 2018

@jaredpalmer bump

@jaredpalmer
Copy link
Owner

can you resolve conflicts?

@morgs32
Copy link
Contributor Author

morgs32 commented Aug 29, 2018

@jaredpalmer how's this?

@ianks
Copy link

ianks commented Aug 30, 2018

While this is good, it doesn't solve the use case in #622 of havin server rendered errors passed in as props. Certain errors cannot be determined by client, so having the ability to pass in initialErrors is still crucial IMO

@jaredpalmer
Copy link
Owner

I thought this was for initialErrors and initialTouched?

@jpserrett
Copy link

The original post #288 mentioned either 'initialErrors' or a 'validateOnLoad' method. Both use cases could be argued for, and may be necessary, but this seems like a great addition that solves an issue a number of people are having.

IMHO, I'd say that this and an 'initialErrors' prop would be two separate, and very useful, additions to the base code. In my use case, I have to make an API call to populate my initialValues, and that API call may return with my errors as well. So when the data is populated, I also need to run my custom validate method to retrieve the errors from the JSON response and apply them to the form.

Just throwing in my $0.02.

@morgs32
Copy link
Contributor Author

morgs32 commented Sep 4, 2018

@jaredpalmer bump

@morgs32
Copy link
Contributor Author

morgs32 commented Sep 6, 2018

@jaredpalmer thoughts?

@morgs32
Copy link
Contributor Author

morgs32 commented Sep 10, 2018

@jaredpalmer beginning to feel:
3x01_the_cabin_show_ 20

@jpserrett
Copy link

Any status on this? Even if its no way, definitely not going to do it?

@vedraan
Copy link

vedraan commented Oct 1, 2018

Is there some estimate on when this might get merged?

There are possible cases where some form fields are no longer valid and you should prevent saving (even though they were at the time of first submit). We need to resort to some hacks to get around this, and having this PR merged would solve all the problems.

@hyperboreans
Copy link

@jaredpalmer @morgs32 we have a use case for this in production and would appreciate an update here. Ideally a merge, or at least a recap on pending issues that are blocking merge.

@morgs32
Copy link
Contributor Author

morgs32 commented Nov 5, 2018

@hyperboreans @vedraan just to be clear I'd love for this to be merged too. @jaredpalmer is a busy guy I guess - or he's just ghosting us til we stop asking. Meanwhile I forked this and manage my own - my therapist says I've got to move on.

@timini
Copy link

timini commented Nov 14, 2018

This looks like exactly what I'm after can we get it merged?

@danvass
Copy link

danvass commented Nov 15, 2018

@jaredpalmer any plans for merging this soon? Also intend to use this and would be great to fetch from npm. Thanks

@kkkkkcnm
Copy link

kkkkkcnm commented Nov 15, 2018 via email

@motiazu
Copy link

motiazu commented Nov 27, 2018

This is nice but wouldn't it be problematic without editing how isValid is calculated?
This line will still regard isInitialValid as the truth when the form state is equal to initialValues.

Edit: Fixed link

@jaredpalmer
Copy link
Owner

In v2, validation is fired on mount by default.

@motiazu
Copy link

motiazu commented Dec 14, 2018

@jaredpalmer Does this mean you will also deprecate isInitialValid? Otherwise, pristine forms will still ignore validation results as I stated in my previous comment in this thread.

@stale stale bot added the stale label Feb 12, 2019
@@ -31,6 +31,7 @@ export class Formik<Values = {}, ExtraProps = {}> extends React.Component<
static defaultProps = {
validateOnChange: true,
validateOnBlur: true,
validateOnLoad: false,
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about validateOnMount. It is not clear when "load" happens

Copy link
Owner

Choose a reason for hiding this comment

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

Agree. Btw this is on by default in v2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is now a good time to use v2?

Copy link
Owner

Choose a reason for hiding this comment

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

YES

Copy link
Owner

Choose a reason for hiding this comment

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

validateOnMount makes the most sense

Choose a reason for hiding this comment

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

I am using v2.0.1-rc.12 but there is still not validateOnLoad flag. Any idea when this very important feature will be released?

Choose a reason for hiding this comment

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

Likewise, forms aren't validating on mount using v2.0.1-rc.13. Is the expectation that we have to setInitialErrors despite guidance above indicating that Formik validates on mount by default in v2?

@stale stale bot removed the stale label Feb 14, 2019
@stale stale bot added the stale label Apr 15, 2019
@stale stale bot removed the stale label Jul 5, 2019
@stale stale bot added the stale label Sep 29, 2019
@stale stale bot removed the stale label Oct 15, 2019
@jaredpalmer
Copy link
Owner

Added back to v2 here: #1913

The default is false.

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.

Initial validation or initialErrors prop