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
Form item error, should be shown first time on blur, not on change #12542
Comments
validateTrigger: "onBlur" |
Hello @tylik1, we use GitHub issues to trace bugs or discuss plans of Ant Design. So, please don't ask usage questions here. You can try to ask questions on Stack Overflow or Segment Fault, then apply tag 你好 @tylik1,Ant Design Issue 板块是用于 bug 反馈与需求讨论的地方。请勿询问如何使用的问题,你可以试着在 Stack Overflow 或者 Segment Fault 中提问(记得添加 |
It is not usage question, it is bad UI experience, and it would be good if additional option is added to show first error onBlur, not onChange. validateTrigger onBlur is not the case. It will always validate on blur, but this behavior should happen only first time, as i've described above, and as it happens on example in Formik. There is no way to make validateTrigger dynamically - e.g. change from 'onBlur' to 'onChange' with state. |
Tested. |
This is still an issue for me with antd version 3.20.7. Errors should not show when user is editing input, for the first time. While it's possible to address this issue by creating handlers for onChange and onBlur that will update the validateTrigger via state. I think it would be better if this was the default behavior. Another example of where this is very frustrating is if you have the following rules for an email field:
It would be much nicer, in my opinion, if the user doesn't see "This input is not a valid Email" while they are typing in their email for the first time. |
Following advice above, this is what I did to work around this issue. Start with
|
@Enalmada thanks for this! I shortened it in my code like so:
and then:
|
@Enalmada @dimasusername Thanks for the idea.
|
I tested the examples above and couldn't get them to work on Antd Form V4. I solved the problem with the code below the three validateTrigger options "onBlur", "onChange" and "OnSubmit". I got a good behavior when necessary to do another type of validation in the field. Ieia is simply to clear the error field when "onBlur" and "onSubmit". Developers could think of something native when choosing these options for validateTrigger.
|
This is definitely the sought after behavior most of the times imo and getting it to work in v4 is really frustrating. Why not provide this sort of behavior out of the box? I'd be happy to do it. |
This is the easy solution I use check email field. In this why first time it use onBlur, after field checked validate type change to onChange.
|
Extending @musacanminaz answer, if you have more than one field that needs this type of behavior, you can build it like this. First of all, define a state containing all field names that will have dynamic validation trigger. Start them with
Next, create a funtion that will update validation trigger of a particular field.
Now, use the function on
The only problem with this approach is when the form is submitted and the fields are invalid, the validation mode will not be updated to
|
This should be the default without writing so much boilerplate |
Developed a custom hook solving exactly this issue. See here and leave an upvote guys! https://stackoverflow.com/a/75962381/12900361 |
Version
3.10.0
Environment
Google Chrome latest version
Reproduction link
Steps to reproduce
type one letter in the field with 2 rules: "required" and "min"
What is expected?
Error should not show when user is editing input, for the first time
What is actually happening?
Error for "min" rule is shown when user edits form input
Expected behavior:
User starts editing form input;
Error is not shown;
User blurs input;
error is shown;
From then on, error is shown on onChange;
I also know there is a validateTrigger which can be set to "onBlur", but it's not the case, it should only work once.
Please visit the link where it works properly with Formik plugin.
https://codesandbox.io/s/lp904qlj1q
The text was updated successfully, but these errors were encountered: