(field: InferField)
| 267 | }; |
| 268 | |
| 269 | const booleanFields = (field: InferField) => { |
| 270 | if (field.type === "boolean") { |
| 271 | imports.push(["Checkbox", "@chakra-ui/react"]); |
| 272 | |
| 273 | if (field.multiple) { |
| 274 | const val = dotAccessor(field.key, undefined, field.accessor); |
| 275 | |
| 276 | const errorVal = `${accessor( |
| 277 | "(errors as any)", |
| 278 | field.key, |
| 279 | undefined, |
| 280 | false, |
| 281 | )}?.[index]`; |
| 282 | |
| 283 | return ` |
| 284 | <> |
| 285 | {${accessor(recordName, field.key)}?.map((item: any, index: number) => ( |
| 286 | <FormControl key={index} mb="3" isInvalid={!!${errorVal}}> |
| 287 | <FormLabel>${translatePrettyString({ |
| 288 | resource, |
| 289 | field, |
| 290 | i18n, |
| 291 | noQuotes: true, |
| 292 | })}</FormLabel> |
| 293 | <Checkbox |
| 294 | {...register(\`${val}.\${index}\`, { |
| 295 | required: "This field is required", |
| 296 | })} |
| 297 | /> |
| 298 | <FormErrorMessage> |
| 299 | {${errorVal}?.message as string} |
| 300 | </FormErrorMessage> |
| 301 | </FormControl> |
| 302 | ))} |
| 303 | </> |
| 304 | `; |
| 305 | } |
| 306 | |
| 307 | return jsx` |
| 308 | <FormControl mb="3" isInvalid={!!${accessor( |
| 309 | "errors", |
| 310 | field.key, |
| 311 | field.accessor, |
| 312 | false, |
| 313 | )}}> |
| 314 | <FormLabel>${translatePrettyString({ |
| 315 | resource, |
| 316 | field, |
| 317 | i18n, |
| 318 | noQuotes: true, |
| 319 | })}</FormLabel> |
| 320 | <Checkbox |
| 321 | {...register("${dotAccessor( |
| 322 | field.key, |
| 323 | undefined, |
| 324 | field.accessor, |
| 325 | )}", { |
| 326 | required: "This field is required", |
no test coverage detected