i need some help on my projet, i try to create a event on my project planning by using formik.
I created a planning form with the creation of a planning in this creation I choose the type of repetition (annual, monthly, daily and weekly) which is displayed in a select this data is retrieved via an API and this call
const fetchTypeEvenement = async () => {
try {
setOnLoadingSelect(true);
const TypeEvenement = await planningService.getTypeEvenement(token, perPage, filters.keyword, sortStatus.columnAccessor, sortStatus.direction, page);
setTypesEvenement(
TypeEvenement.items.data.map((data: { id: number; intitule: string }) => {
return { value: data.id, label: data.intitule };
}),
);
setOnLoadingSelect(false);
} catch (error) {
console.error("Erreur lors de la récupération des types d'événement", error);
}
};
in the rest of the form there are fields which depend on the type of repetition, what I would like is that when I change the type of repetition the fields linked to another type of repetition reset to zero, yesterday I I tested the method with handles but it doesn’t work.
this is what i try to reset the inputs when i want to change the type of repetition
const handleRepetitionChange = (e: any, setFieldValue: any) => {
let value = {}
const selectedValue = e.target.value;
setFieldValue('id_type_repetition', selectedValue);
if (parseInt(selectedValue) === 3) {
// Réinitialisez le champ jour_semaine lorsque le type de répétition est 3
setFieldValue('jour_semaine', []);
}
};
<FieldSelectFormFormik
id={'id_type_repetition'}
label={'Type de répétition'}
submitCount={submitCount}
error={errors.id_type_repetition}
onLoadingSelect={onLoadingSelect}
setKeyword={setKeywordRepetitions}
options={typesRepetitions}
widthLabel="w-[168px]"
onChangeSelect={(e: any, options: any) => handleRepetitionChange(e, options)}
/>
TypeError: Cannot read properties of undefined (reading ‘value’)
sofiane is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1