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

184
Vistas
How can I set the value of a Form.Item without a form object in Ant.Design?

I have custom Form Item component and I want to add hidden input, but I can't update value without Ant Form object (Form.useForm();

const selectBefore = (
   <Select
       onChange={value => {/*HOW TO SET NEW VALUE FOR <Input name='term-type'/> ?*/}}
    >
         <Select.Option value="date">Date</Select.Option>
         <Select.Option value="number">Number</Select.Option>
</Select>
);

const InputType = termType === 'date' ? DateInput : Input;

return (
        <>
            <InputType
                addonBefore={selectBefore}
                {...rest}
            />

            <Form.Item
                name='term-type'
                initialValue={termType}
                style={{display: 'none'}}
            >
                <Input
                    type="text"
                    value={termType}
                />
            </Form.Item>
        </>
    );
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can remove the Input part altogether instead of keeping it hidden to use its value. Try this:

<Select onChange={value => setTermType(value)}}>
     <Select.Option value="date">Date</Select.Option>
     <Select.Option value="number">Number</Select.Option>
</Select>

Then you can use termType as state, and it will be updated as the Select value changes. I suggest that you should add a placeholder or default initial value to Select component as

<Select defaultValue="date" onChange={value => setTermType(value)}}>
     <Select.Option value="date">Date</Select.Option>
     <Select.Option value="number">Number</Select.Option>
</Select>
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use useState hook and set the value to the state and don't use Form.useForm() and Form.Item at all:

const [ termType, setTermType ] = useState("");

...

<Select onChange={value => setTermType(value)}}>
     <Select.Option value="date">Date</Select.Option>
     <Select.Option value="number">Number</Select.Option>
</Select>

...

<Input
    type="text"
    value={termType}
/>
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