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

Added email validation to ForgotPasswordForm #1997

Merged
merged 9 commits into from
Dec 10, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import Button from '../../Button';
import Field from '../../Field';
import TextInput from '../../TextInput';

import { isRequired } from '../../../util/formValidators';
import { isRequired, validateEmail } from '../../../util/formValidators';
import combine from '../../../util/combineValidators';

import { mergeClasses } from '../../../classify';
import defaultClasses from './forgotPasswordForm.css';
Expand All @@ -25,8 +26,7 @@ const ForgotPasswordForm = props => {
<TextInput
autoComplete="email"
field="email"
validate={isRequired}
validateOnBlur
Copy link
Contributor

Choose a reason for hiding this comment

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

Before @dpatil-magento merges maybe @revanth0212 can explain why we had to remove this. I feel like the validation should happen on blur and before submit, but it seems like it wasn't happening correctly.

Copy link
Contributor

Choose a reason for hiding this comment

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

The issue with validateOnBlur is that it only validates on blur. So once you enter a new valid email address and click on the submit button, the validation is not done yet and the click won't be registered because clicking button === losing focus for the email field but the validation result will only propagate in the next render. That is the reason why @dpatil-magento had to click twice.

validate={combine([isRequired, validateEmail])}
gaurav-473 marked this conversation as resolved.
Show resolved Hide resolved
/>
</Field>
<div className={classes.buttonContainer}>
Expand Down