Validation not working after reset
See original GitHub issueHere is the code
import React from 'react';
import PropTypes from 'prop-types';
import { Link, Redirect } from 'react-router-dom';
import { Field, reduxForm } from 'redux-form';
import { connect } from 'react-redux';
import { Section, RenderField, Block } from 'components';
import { validateRegisterForm as validate } from 'utils/validations';
import { forgotPassword } from 'redux/modules/auth';
const mapStateToProps = state => {
const { sending, sendSuccess } = state.auth;
return { sending, sendSuccess };
};
const reduxFormDecorator = reduxForm({
form: 'ForgotPasswordForm',
validate,
});
const reduxConnector = connect(mapStateToProps, { forgotPassword });
class ForgotPassword extends React.Component {
static propTypes = {
sending: PropTypes.bool,
forgotPassword: PropTypes.func.isRequired,
handleSubmit: PropTypes.func.isRequired,
};
static defaultProps = {
sending: false,
sendSuccess: false,
};
componentWillReceiveProps(nextProps) {
if (nextProps.sendSuccess) {
this.props.reset();
}
}
handleFormSubmit = data => {
this.props.forgotPassword(data);
};
render() {
const { handleSubmit, reset, sending } = this.props;
return (
<div>
<Section>
<div className="form-popup">
<div className="form-popup-content">
<Block loading={sending}>
<form
id="register-form"
name="register-form"
method="POST"
onSubmit={handleSubmit(this.handleFormSubmit)}
>
<Field
name="email"
type="email"
component={RenderField}
label="Alamat Email"
description="contoh: email@example.com"
/>
<button type="submit" className="button mid primary m-bottom-25">
Reset
</button>
</form>
</Block>
</div>
</div>
</Section>
</div>
);
}
}
export default reduxConnector(reduxFormDecorator(ForgotPassword));
At first validation works well. but when form is submitted and this.props.reset()
is called (the input become empty) and I try to submit it again it not validate the input (input is empty).
Issue Analytics
- State:
- Created 6 years ago
- Reactions:29
- Comments:83 (3 by maintainers)
Top Results From Across the Web
Validation not working after clear the form - Stack Overflow
After resetting the form you are running validations manually by calling setErrors(null). setErrors(null) means you are setting the form ...
Read more >Field validation not triggered after reset · Issue #2838 - GitHub
The issue is only happening when "Age" is the only field populated when the form is reset. In other words, validation is being...
Read more >Reactive Form - Reset input validation after change
I believe the reason your Form wasn't resetting was because of the 'Built-In Validations' Property of your Delete button. When set to 'Built-In...
Read more >angular reset form without triggering validation - You.com
The problem was discussed in issue #7113 on GitHub. It is caused by the fact that validation is performed when the input field...
Read more >Validation required field error after resetting the properties
I have an update user password form in my application which is working fine except when I reset the fields using $this->reset(['current_password', ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I solved this by forcing validation using the
shouldValidate
config.I’m using Redux Form 7.1.2 with React 16 and came up with this solution: