question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Validation not working after reset

See original GitHub issue

Here 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:open
  • Created 6 years ago
  • Reactions:29
  • Comments:83 (3 by maintainers)

github_iconTop GitHub Comments

15reactions
SafalPandeycommented, Jul 1, 2020

I solved this by forcing validation using the shouldValidate config.

reduxForm({
  // Set to always validate
  shouldValidate: () => true,

  // Other config options...
})```
15reactions
Landishcommented, Nov 21, 2017

I’m using Redux Form 7.1.2 with React 16 and came up with this solution:

shouldError: ({ props }) => {
  return !props.anyTouched;
}
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found