formik: Track warnings like errors
Currently a field is either invalid or valid. In most form-heavy applications there is a grey area where a value might be outside of some “known good” parameter but not necessarily invalid, resulting in a warning that doesn’t affect form-validity but is still composed of validation functions. Extending this thinking, it’s possible that fields might have a number of meta states (with errors and warnings being just two) that can be built out of validators. One such (real-world) example is a “visibility” state: Is some condition met (or not met)? Then this field (or group of fields) should have their visibility affected.
I filed a similar issue for redux-form (which already has warnings) a while ago but have since shied away from redux-form.
I think this could be implemented in a future proof way (while retaining backwards compatibility) by introducing a new setter function and a new render prop (an object mapping validation type keys error, warning, etc. to objects of validation results).
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 32
- Comments: 35 (3 by maintainers)
+1 for the issue.
Fairly big shortcoming for what is supposed to be the go-to form management library. Formik might be “very flexible” and allow you to implement this on your own. But so is vanilla html/js; I’m using a library to save time.
Pretty sure there’s enough upvotes here to say this should be more than an “enhancement”. At the very least this issue should be reopened/re-considered.
Here’s an example of a warning from our application
I would also love this feature!
I have the requirement for
infoandwarningvalidations on a project that I’m working on at the moment.Example warning
Can we re-open this? @jaredpalmer It seems like a feature that a lot of people are interested in.
@jaredpalmer Let’s reopen this! 😃
Formik is very flexible. You can achieve this in many ways. I attempted to recreate warning like validation messages, here is the code https://codesandbox.io/s/xppooqx884
Edit: I see, errors block form submission.
@jaredpalmer it will be an awesome enhancement. Let’s reopen this.
@jaredpalmer Is this going to be a thing in the future? I’d like to see this feature implemented as well! 😃
well, need some warnings/information on a field without making it invalid and found this issue So +1 to “it would be awesome to have warnings”
Can you give me an example of a warning? I have yet to truly see one in the wild.
Difference between @Andreyco’s implementation and redux-form is that warn in redux-form does not mark a form as invalid stopping submission
In redux-form as the name implies, a warning is just a notice that the user can then override. Allows for flexibility
I would love to have this feature added too. Thanks.
@jaredpalmer In our form-heavy application we have cases where it’s important we capture as much valid data upfront as possible but we’re hesitant to outright declare some user input as invalid because the rules would be arbitrary ones made up by ourselves (“How long have you lived here?”) and could prevent valid (but perhaps extreme) input from being submitted, a warning deals with “fat finger” cases like these quite well in my experience.
@prichodko Status sounds like it can only have one value which seems somewhat limiting? Is my assumption incorrect?
Would love this feature as well!🙌
An example of a warning for https://github.com/jaredpalmer/formik/issues/389#issuecomment-367707645
Generally, sometimes a specific form input can have non-obvious side effects and a validation warning would be an effective way to inform the user about those side effects.
Here’s my specific example: In our app there is a special “AccountOwner” role with special privileges and only one user can be assigned to this role at a time. When editing a User, selecting this special role has the side effect of also removing the role from whoever currently holds that role. To that end, we’d like to be able to include a validation warning that only appears when this special value is selected in the select input.
Could we re-architect our app around this and do away with the special role? Yes, technically, but that’s completely infeasible. Having validation warnings similar to validation errors would be a nice way to address the issue. Our working alternative involves special case logic and form state, which is uncomfortable to say the least.
+1
+1
Oh sheez this feature is what i’m looking for!! Any updates so far? BUMP
I just check if the field has been touched and treat it like anything I’d want to conditionally render based on a piece of state in React
Formik doesn’t really need to help here
Just like you don’t need it to conditionally change input placeholders or hints like here in a no-context sample of a form field 😇
@jaredpalmer any updates on this? I see PR is up and author has added tests. Just started using Formik and bumped into issue of missing warnings as they are needed for my usecase 😃