0

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;
  }
};
lpizzinidev
  • 12,741
  • 2
  • 10
  • 29
Nidhi Mahajan
  • 81
  • 1
  • 7
  • Does this answer your question? [Can I append an array to 'formdata' in javascript?](https://stackoverflow.com/questions/14026539/can-i-append-an-array-to-formdata-in-javascript) – Emanuele Scarabattoli Jul 11 '22 at 11:59
  • not working. I just to save ['A stage is required', 'Themed decoratiions are essential to my event'] values in different column when i call api – Nidhi Mahajan Jul 11 '22 at 12:10

0 Answers0