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

101
Visualizações
ReactJS: RadioButton on reset

I have a form in which I have avRadioButton.

When I click on one of this radioButton, I save the value "S" or "N". But when I click on resetForm the value is set on empty string, but the radio button remains checked ( so if I click on submit form another time the radioButton's value is taken)

    const [formModel, setFormModel] = useState({
        //... other fields
        perFlgattivo: '',
      });
    
    const handleFormReset = e => {
        setFormModel({
        //... other fields
          perFlgattivo: '',
        });  
    }
    
    const handleChangeRadio = e => {
        const { name, value } = e.target;
        console.log("e.target ", e.target)
        setFormModel(prevState => ({
          ...prevState,
          [name]: value,
        }));
      };

and this is my radioButton in the form:

    <AvRadioGroup name="perFlgattivo" inline>
                        <Label id="perFlgattivo">Active</Trans>
                        </Label>
                        <br></br>
                        <AvRadio
                          id="perFlgattivo"
                          name="perFlgattivo"
                          data-cy="perFlgattivo"
                          label="Si"
                          value="S"
                          onChange={handleChangeRadio}
                          checked={formModel.perFlgattivo}
                        />
                        <AvRadio
                          id="perFlgattivo"
                          name="perFlgattivo"
                          data-cy="perFlgattivo"
                          label="No"
                          value="N"
                          onChange={handleChangeRadio}
                          checked={formModel.perFlgattivo}
                        />
                      </AvRadioGroup>

So my problem is when I'm trying to clear the value, because even if the formModel.perFlgattivo results an empty string, the value in the form remains checked

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

0

This is a very rude solution, but checked={formModel.perFlgattivo.length > 0} will surely solve your problem.

Вut in general radio buttons should have boolean in value field. Try changing perFlgattivo default value to false and same on form reset.

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