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

On blur function is being called after the submit on React Native #3592

Open
pedrohenriiz opened this issue Jun 24, 2022 · 1 comment
Open

Comments

@pedrohenriiz
Copy link

Bug report

Current Behavior

I'm using Formik on a React Native app and I have two fields, discount percentage and discount value. When I change the discount percentage, the discount value changes and vice versa. I execute this process at onBlur function. But, when the user clicks to submit the form, the submit function is executing before the onBlur is called.

issue

Additional context

I made a workaround using a state, verifying if the field has already passed on onBlur function, on submit function, but I think this is not the best approach.

async function onSubmit({
discountPercentage: newDiscountPercentage,
discountValue: newDiscountValue,
totalProducts: newTotalProducts,
total: newTotal,
paymentMethodId: newPaymentMethodId,
observation: newObservation,
},
{ setSubmitting, setFieldError }
) {
console.log('On submit');
if (!isValidToSubmit) {
   setFieldError('discountPercentage', 'message');
   toast.error('message!');
   return setSubmitting(false);
}

Also, I'm using the useFormik hook with this settings

const {
   handleChange,
   handleSubmit,
   handleBlur,
   values,
   errors,
   touched,
   setFieldValue,
   dirty,
  } = useFormik({
   initialValues,
   onSubmit,
   validationSchema: ValidationSchema(totalProducts),
 });

If more info is needed, I can provide more, but, since the project has a lot of fields and details, I can't provide any reproducible code.

Your environment

Software Version(s)
Formik 2.2.8
React 17.0.1
React Native 0.64.1
@kdkaushikdalvi
Copy link

I'm also facing similar issue on 2.2.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants