mercredi 22 janvier 2020

currentValue.indexOf is not a function at getValueForCheckbox in Formik

I'm trying to build a group checkbox component with formik as in the photo table of checkbox group

My checkbox componet code is:

const CheckBox = ({ children, ...props }) => {
  const [field, meta] = useField({ ...props, type: "checkbox" });
  return (
    <>
      <label className="form-check-label">
        <input type="checkbox" {...field} {...props} />
        {children}
      </label>
      {meta.touched && meta.error ? (
        <div className="text text-danger">{meta.error}</div>
      ) : null}
    </>
  );
};

and this is the implementation of checkbox group:

                <tbody>
                  {data.day_of_week
                    ? data.day_of_week.map((day, index) => (
                        <tr key={index}>
                          <th scop="row">{day[1]}</th>
                          {data.periods
                            ? data.periods.map((time, index) => (
                                <td key={index}>
                                  <CheckBox
                                    name="acceptedTime"
                                    key={index}
                                    value={time[0]}
                                  />
                                </td>
                              ))
                            : null}
                        </tr>
                      ))
                    : null}
                </tbody>
              </table>

When I click on each of these checkboxes I get the error currentValue.indexOf is not a function.

Thank you so much for your help




Aucun commentaire:

Enregistrer un commentaire