marsoon
marsoon

Reputation: 21

react-hook-form do not send PasswordConfirm

Hello guys I'm using react-hook-form library it's really awesome library for me !

but I have some problem at this time I don't want to send pwdConfirm value, cuz this value gets me 400 erros, so How can I send values without pwdConfirm ?

I just only want to send id , pwd , nickname !

    const dispatch = useDispatch();
const { register, watch, errors, handleSubmit } = useForm();
const password = useRef();
password.current = watch('password');
const type = 'normal';
const onSubmit = (data) => {
    console.log(data);
    dispatch(signUpRequest(data));
};
useEffect(() => {});
return (
    <>
        <form
            onSubmit={handleSubmit(onSubmit)}
            className={styles.signup__form}
        >
            <label>email</label>
            <input
                name="email"
                type="text"
                ref={register({ required: true, pattern: /^\S+@\S+$/i })}
                placeholder="&#xf0e0;"
            />
            {errors.email && (
                <p className={styles.error__message}>
                   incorrect email
                </p>
            )}

            <label>password</label>
            <input
                name="password"
                type="password"
                ref={register({ required: true, minLength: 6 })}
                placeholder="&#xf09c;"
            />
            {errors.password && errors.password.type === 'required' && (
                <p className={styles.error__message}>
                    password plz
                </p>
            )}
            {errors.password && errors.password.type === 'minLength' && (
                <p className={styles.error__message}>
                   at least 6character
                </p>
            )}

            <label>password confirm </label>
            <input
                type="password"
                name="pwdConfirm"
                ref={register({
                    required: true,
                    validate: (value) => value === password.current,
                })}
                placeholder="&#xf09c;"
            />
            {errors.pwdConfirm && errors.pwdConfirm.type === 'required' && (
                <p className={styles.error__message}>
                   check your password
                </p>
            )}
            {errors.pwdConfirm && errors.pwdConfirm.type === 'validate' && (
                <p className={styles.error__message}>
                  not correct your password
                </p>
            )}

Upvotes: 0

Views: 64

Answers (1)

Antier Solutions
Antier Solutions

Reputation: 1402

I have used the delete operator of javascript to remove pwdConfirm key from an existing object.

const onSubmit = (data) => {
    delete data.pwdConfirm
    console.log(data);
    dispatch(signUpRequest(data));
};

Upvotes: 2

Related Questions