Advertisement
Guest User

Untitled

a guest
Mar 4th, 2024
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 2.52 KB | Source Code | 0 0
  1. <FormField
  2.                 control={form.control}
  3.                 name="items"
  4.                 render={() => (
  5.                   <FormItem>
  6.                     <div className="mb-4">
  7.                       <FormLabel className="text-base">
  8.                         TCET Assistance
  9.                       </FormLabel>
  10.                     </div>
  11.  
  12.                     {items.map((item) => (
  13.                       <FormField
  14.                         key={item.id}
  15.                         control={form.control}
  16.                         name="items"
  17.                         render={({ field }) => {
  18.                           return (
  19.                             <FormItem
  20.                               key={item.id}
  21.                               className="flex flex-row items-start space-x-3 space-y-0"
  22.                             >
  23.                               <FormControl>
  24.                                 <Checkbox
  25.                                   checked={field.value?.includes(item.id)}
  26.                                   onCheckedChange={(checked) => {
  27.                                     // Ensure field.value is an array before using methods like includes() and filter()
  28.                                     if (Array.isArray(field.value)) {
  29.                                       field.onChange(
  30.                                         checked
  31.                                           ? [...field.value, item.id]
  32.                                           : field.value.filter(
  33.                                               (value) => value !== item.id
  34.                                             )
  35.                                       );
  36.                                     } else {
  37.                                       // If field.value is not an array, handle the case accordingly
  38.                                       // For example, set it to an empty array if appropriate
  39.                                       field.onChange(checked ? [item.id] : []);
  40.                                     }
  41.                                   }}
  42.                                 />
  43.                               </FormControl>
  44.                               <FormLabel className="text-sm font-normal">
  45.                                 {item.label}
  46.                               </FormLabel>
  47.                             </FormItem>
  48.                           );
  49.                         }}
  50.                       />
  51.                     ))}
  52.  
  53.                     <FormMessage />
  54.                   </FormItem>
  55.                 )}
  56.               />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement