The senerio is that when choose categories using checkbox those checked box who are slected save their values in db in different column.
const checkListNames = check.map((item) => item.name)
values in want to save in different columns. Getting output such as :
['A stage is required', 'Themed decoratiions are essential to my event'].
Want to save these values in different columns
const handleSubmit = (e) => {
e.preventDefault();
if (check.length > 0) {
const checkListNames = check.map((item) => item.name);
let formData = new FormData();
formData.append('list_category', categoryId);
formData.append('name', checkListNames);
formData.append('event_id', get_all_data.data7);
formData.append('created_by', '629829078779cc4a00139c9a');
for (var pair of formData.entries()) {
console.log(pair[0] + ' - ' + pair[1]);
}
api
.post('checklist', formData)
.then((response) => {
const { data } = response;
if (data.status == '1') {
toast.success('Checklist added successfully');
history.push('/CheckList');
} else {
toast.error('Something went wrong !');
}
})
.catch((error) => {
throw error;
});
} else {
toast.error('Select atleast one category');
return false;
}
};