-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
The form error appears and disappears when I press submit. #6101
Comments
I do not understand the issue. It works exactly as coded in the sandbox |
Ok I renewed sandbox. Removed clearErrors. I expect that the error message when clicking the button will always be displayed. This was the case in previous versions of mantine. Now, the first time I click, an error appears. On the second press it disappears, although it should have remained |
It work how I expected in version 7.7.2. Forked box https://codesandbox.io/p/sandbox/mantine-7-8-form-error-forked-d6kxc2 |
I have the same problem. An error set via Current workaround that works for me: const onSubmit = () => {
if (Object.keys(form.errors).length !== 0) {
form.setErrors(form.errors); // otherwise Mantine will "forget" the current errors that still exist
return;
}
}; |
…` not working correctly in some cases (#6101)
Things that you can do in next patch: form.onSubmit(() => {
// async operation to update error state. It can be Promise.resolve for sync operation to show error instantly
Promise.resolve().then(() => form.setFieldError('email', 'Server error'));
}); |
Thank your for answering and thanks for this great library! Maybe it would be more beneficial to check if the value was changed? Here is a common example where this is relevant. Imagine a registration form with a user name login. User names need to be unique, so that the server might respond with an error if the name is already taken. Minimal code example: const form = useForm({
initialValues: {
username: '',
// ...
},
});
async function submit(data) {
const answer = await makeRequestSomehow();
if (answer.errorUserNameIsAlreadyInUse) {
form.setFieldError('username', 'Sorry, your username is already in use.');
}
} I think the best developer experience would be to simply keep the error for |
There should not be any issue with async operations with the next patch – the error will be set to the given value in your example. The only issue that will remain is sync operations. |
I see. Thanks for clarifying! :) |
Fixed in 7.10.1 |
Dependencies check up
What version of @mantine/* packages do you have in package.json?
7.8.0
What package has an issue?
@mantine/form
What framework do you use?
Vite
In which browsers you can reproduce the issue?
All
Describe the bug
I have a form. When I click on the confirm button, I clear all errors and make a request to the server. With some answer, I need to put an error in the field, but the error appears and disappears one by one.
If possible, include a link to a codesandbox with a minimal reproduction
https://codesandbox.io/p/sandbox/mantine-7-8-form-error-rpnxw7
Possible fix
No response
Self-service
The text was updated successfully, but these errors were encountered: