Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

218
Visualizações
How to prevent a form input value from disappearing on click in other fields?

The form campaignid input value is automatically filled in when the page is loaded. When I click on the other fields, it reset to default.

What can I do to prevent default and preserve my campaignid input value?

I'm using a third party script to get URL parameters and insert them into campaignid value.

import { Button, FormControl, Input } from "@chakra-ui/react";
import { Field, Form, Formik } from "formik";

import Script from "next/script";

export default function FormikExample() {
  return (
    <>
      <Script src="https://cdn.jsdelivr.net/gh/gkogan/sup-save-url-parameters/sup.min.js" />

      <Formik
        initialValues={{
          name: "",
        }}
        onSubmit={(values) => {
          setTimeout(() => {
            fetch(`https://hooks.zapier.com/hooks/catch/3660927/bte5w77/`, {
              method: "POST",
              body: JSON.stringify(values, null, 2),
            }),
              3000;
          });
        }}
      >
        {(props) => (
          <Form id="hero">
            <Field name="name">
              <FormControl>
                {({ field }) => <Input {...field} type="text" id="name" />}
              </FormControl>
            </Field>

            <Field name="email">
              <FormControl>
                {({ field }) => <Input {...field} type="email" id="email" />}
              </FormControl>
            </Field>

            <Field name="campaignid">
              {({ field }) => (
                <FormControl isReadOnly>
                  <Input {...field} type="hidden" value="" id="campaignid" />
                </FormControl>
              )}
            </Field>

            <Button id="submited" isLoading={props.isSubmitting} type="submit">
              Submit
            </Button>
          </Form>
        )}
      </Formik>
    </>
  );
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to prevent the default of the submit form. Use prevent default on your submit function, it will stop that behaviour. More info: https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault

e.preventDefault()
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda