Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

97
Vistas
React Formik checkbox condition based value remove in other Fields

I am using react-formik for form I have one issue with checkbox based condition, the check relation to another two fields if user checked the hidden fields are showing else it's hidden, the user unchecked the remaining two contains values, but I want if user unchecked all fields to empty.

My code:

Edit ConditionCheck

Thanks for help

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

when you want to control the value of one field based on the value of other field you can make use of the setFieldValue provided by Formik.

The Field components has a render prop which is a function and which helps us to access the setFieldValue in its argument. Now with the setFieldValue being accessible you can use it set the value of the dependent fields when the checkbox is checked or unChecked.

You need to render the Field component for your checkbox as below

<Field
  name="airconditioning"
  render={({ meta, form }) => {
    return (
      <Checkbox
        checked={meta.value}
        onChange={(e) => {
          const { checked } = e.target;
          if (!checked) {
            form.setFieldValue("airconditioningType", "");
            form.setFieldValue("airconditioningStarred", "");
          }
          form.setFieldValue("airconditioning", checked || "");
        }}
        name="checkedB"
        color="primary"
      />
    );
  }}
/>

Working Sandbox

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda