vendredi 3 décembre 2021

Get Values of dynamically added checkboxes in React

I am just fighting with the values of dynamically added checkboxes in React with MUI.

I have a list of values where those checkboxes are created and now I would need the status checked or not of those ones.

Code of generation of the checkbox:

const country = ['Österreich', 'Deutschland', 'Schweiz', 'Nordeuropa', 'Westeuropa',
        'Mitteleuropa', 'Osteuropa', 'Südosteuropa', 'Südeuropa', 'Gesamt-Europa'];

<FormControl component="fieldset" sx=>
     <RadioGroup
           aria-label={"decisionMakerCountry"+props.id}
           name={"decisionMakerCountry"+props.id}
           defaultValue={props.formData !== null && props.formData !== undefined ? props.formData["decisionMakerCountry"+props.id] : ''}
       >
         {
             country.map((field, index) => (
                     <FormControlLabel value={field} control={<Checkbox/>} label={field}
                         key={index}/>
             ))
         }
      </RadioGroup>
</FormControl>

How I get all other values of the form:

const handleNext = async (event) => {
        event.preventDefault();
        const formData = new FormData(event.currentTarget);
        handleFormData(formData);
}

For all other fields e.g. textfields, Radiobuttons, ... I receive the data correctly, just for the checkbox it is not working.

Thank you for all your answers!




Aucun commentaire:

Enregistrer un commentaire