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

113
Visualizações
Check if group of several radio buttons is checked in React

I'm implementing a simple e-commerce that has a shopping cart. In my project there will be a page that displays all the details of the single product. In which there will be multiple selection of different attributes, which is going to be radio buttons. For instance, iPhone 13 has attributes like color and capacity. These attributes are coming from a GraphQL endpoint.

What I want to do is to create an ADD TO CART button. Before adding the product to the cart all attributes must be CHECKED.

Here is my code for rendering the attributes.

    {this.state.product.attributes.map(attribute=>{
    return (
        <>
            <h5>{attribute.name.toUpperCase() + ":"}</h5>
            <>
                {attribute.items.map(item =>{
                    return (
                        <>
                            <input onClick={()=>{}} type="radio" id={item.id + " " + attribute.name} name={attribute.name} value={item.value}/>
                            <label htmlFor={item.id + " " + attribute.name}>{item.displayValue}</label>
                        </>
                    )
                })}
            </>
        </>
    )
})}

Also, here is my code for the button

<button onClick={()=>{addProduct(this.props.id, this.state.product.prices)}}>ADD TO CART</button>

Let me know what should I do?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It's hard to say what exactly you should do without seeing the rest of your component. However, I highly recommend looking at React's documentation on forms. Namely, you probably want to see their example on Controlled Components to track the state of each attribute.

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