-
-
Notifications
You must be signed in to change notification settings - Fork 44
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Field with error is not focused when field is disabled while submitting #10
Comments
When you click the submit button, the form is submitted. The validation is a part of it and if your fields are disabled, they probably can't be focused. Therefore, this is currently the expected behavior. Why do you disable the fields when the form is submitted? I have not seen this on any login form yet. I would disable the submit button so that the form cannot be submitted while it is being submitted. |
The login form is just an example of what I meant and how I implemented it. I simply disable the fields so the user can't edit them until he gets the response back. Now I'm wondering whether it is a good idea or not. I think of one use case, let's say you have client validation that passes, so you take that form data and send it to the server. The server does some validation & business logic, and it sends back 4xx error with an error related to some fields. You render the error along the field, but the user had changed the field's value before the response was acquired. Now the error & value are out of sync. However, as you've said, disabling the submit button is the core thing here. Maybe disabling fields is a bad UX pattern, but I'd probably find few forms where it made sense, so I'll leave the decision whether to "fix" this up to you, but I think it seems natural to try to focus the error field only after when the form stops submitting. |
I took a quick look at react-hook-form and it seems that's exactly how it's implemented there. If you want to disable the fields during submission but not during validation, you can write the following: However, I think that the fields should not be disabled. Normally a user does not change his input during submission because, for example, a loading animation is displayed, and if he does, he should be able to understand why an error message is displayed incorrectly due to his change. |
Yeah disabling fields during submitting isn't probably a great idea in the end. I'll close this issue, thank you for the discussion and hopefully, I didn't waste your time! :D |
Hey 馃憢,
It seems like Fields that have
isDisabled={form.isSubmitting}
can't be focused when an error is present. I think this is unexpected.Example form:
The text was updated successfully, but these errors were encountered: