调用handleSubmit时禁用验证

时间:2019-01-24 00:00:25

标签: reactjs validation redux redux-form

正如标题所说,id希望在调用Submit时禁用验证。 这可能吗 ? 或者我可以通过props访问函数中的字段值吗?

更新 这是有问题的组件

我需要的是,处理submit不会再次进行验证,并且会立即调用submitRegister

    class RegisterPage extends Component { 

    submitRegister = values => {

        this.props.register(values.username, values.password);

    };


    render() {

        let formInvalid = this.props.invalid;

        let { fetchState, submitting } = this.props;

        return (

            <AuthWrapper>

                <RegisterForm

                    onSubmit={this.props.handleSubmit(this.submitRegister)}

                >

                    <PageLabel>Register</PageLabel>

                    <Field

                        name="username"

                        type="text"

                        component={this.renderInputField}

                        label="Username"

                        gridArea="Username"

                    />

                    <Field

                        name="password"

                        type="password"

                        component={this.renderInputField}

                        label="Password"

                        gridArea="Password"

                    />

                    <Field

                        name="passwordRepeat"

                        type="password"

                        component={this.renderInputField}

                        label="Repeat Password"

                        gridArea="PasswordRepeat"

                    />

                    <RegisterButton

                        type="submit"

                        disabled={formInvalid || submitting}

                    >

                        {fetchState.loading &&

                        (fetchState.fetchType === fetchTypes.register ||

                            fetchState.fetchType === fetchTypes.login) ? (

                            <GridLoader

                                size={10}

                                sizeUnit={'px'}

                                css={'margin: auto;'}

                                color={'white'}

                            />

                        ) : (

                            'Register'

                        )}

                    </RegisterButton>

                </RegisterForm>

            </AuthWrapper>

        );

    }

}


RegisterPage.propTypes = {

    register: PropTypes.func.isRequired

};


const mapStateToProps = ({ fetch }) => ({

    fetchState: fetch

});


const mapDispatchToProps = {

    register

};


export default connect(

    mapStateToProps,

    mapDispatchToProps

)(

    reduxForm({

        form: 'registerForm',

        validate,

        asyncValidate: checkUsername,

        asyncChangeFields: ['username']

    })(RegisterPage)

);

0 个答案:

没有答案