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

102
Views
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 answers
Answer question

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 Report
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!