Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
cómo permitir que el usuario solo elija un botón de radio reaccionar dinámicamente

Tengo datos JSON y creé un formulario dinámico y tengo algunos botones de radio y dije que si el tipo de pregunta era por ejemplo 3, represente el componente RadioBtn y hay algunas preguntas que tienen el tipo 3. Solo quiero permitir que el usuario para elegir solo un botón de opción y traté de obtener el atributo de nombre, pero el problema es que cuando tengo 3 preguntas que tienen el tipo 3, cuando elijo un botón de opción en la primera pregunta y elijo para la segunda pregunta, la respuesta para la primera pregunta se ha ido!!! ¡y es por eso que todas las preguntas tienen un atributo de nombre y no sé qué hacer!

 const Elements = ({ question, handleChange }) => { console.log(question.type); switch (question.type) { case 0: case 1: return <Input question={question} handleChange={handleChange} />; case 2: return <DatePick question={question} handleChange={handleChange} />; case 3: return <RadioBtn question={question} handleChange={handleChange} />; default: return null; } }; export default Elements;

y este es el componente RadioBtn:

 import React, { useContext } from "react"; import { FormContext } from "./FormContext"; const RadioBtn = ({ question, handleChange }) => { console.log("id", question.id); return ( <div> <label>{question.text}</label> <label style={{ color: "gray", fontSize: "12" }}> {question.helptext ? question.helptext : null} </label> {question.list.map((el) => ( <div> <label>{el}</label> <input type="radio" name="radioBtn" value={el} onChange={(e) => handleChange(question.id, e)} /> </div> ))} </div> ); }; export default RadioBtn;
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!