|
6 | 6 | import React, { useState } from 'react'; |
7 | 7 |
|
8 | 8 | import { |
9 | | - PydanticFormControlledElementProps, |
10 | | - PydanticFormFieldOption, |
| 9 | + PydanticFormControlledElementProps, |
| 10 | + PydanticFormFieldOption, |
11 | 11 | } from '@/types'; |
12 | 12 |
|
13 | 13 | export const ListField = ({ |
14 | | - value, |
15 | | - onChange, |
16 | | - onBlur, |
17 | | - disabled, |
18 | | - pydanticFormField, |
| 14 | + value, |
| 15 | + onChange, |
| 16 | + onBlur, |
| 17 | + disabled, |
| 18 | + pydanticFormField, |
19 | 19 | }: PydanticFormControlledElementProps & { |
20 | | - options?: Array<{ value: string; label: string }>; |
| 20 | + options?: Array<{ value: string; label: string }>; |
21 | 21 | }) => { |
22 | | - const [listItems, setListItems] = useState(value || []); |
| 22 | + const [listItems, setListItems] = useState(value || []); |
23 | 23 |
|
24 | | - return ( |
25 | | - <div> |
26 | | - <select |
27 | | - onBlur={onBlur} |
28 | | - disabled={disabled} |
29 | | - value={listItems} |
30 | | - onChange={(e) => { |
31 | | - const selectedValues = Array.from( |
32 | | - e.currentTarget.selectedOptions, |
33 | | - (option) => option.value |
34 | | - ); |
35 | | - setListItems(selectedValues); |
36 | | - onChange(selectedValues); |
37 | | - }} |
38 | | - multiple |
39 | | - > |
40 | | - {pydanticFormField.options.map( |
41 | | - (option: PydanticFormFieldOption) => ( |
42 | | - <option key={option.value} value={option.label}> |
43 | | - {option.label} |
44 | | - </option> |
45 | | - ) |
46 | | - )} |
47 | | - </select> |
48 | | - </div> |
49 | | - ); |
| 24 | + return ( |
| 25 | + <div> |
| 26 | + <select |
| 27 | + onBlur={onBlur} |
| 28 | + disabled={disabled} |
| 29 | + value={listItems} |
| 30 | + onChange={(e) => { |
| 31 | + const selectedValues = Array.from( |
| 32 | + e.currentTarget.selectedOptions, |
| 33 | + (option) => option.value, |
| 34 | + ); |
| 35 | + setListItems(selectedValues); |
| 36 | + onChange(selectedValues); |
| 37 | + }} |
| 38 | + multiple |
| 39 | + > |
| 40 | + {pydanticFormField.options.map( |
| 41 | + (option: PydanticFormFieldOption) => ( |
| 42 | + <option key={option.value} value={option.label}> |
| 43 | + {option.label} |
| 44 | + </option> |
| 45 | + ), |
| 46 | + )} |
| 47 | + </select> |
| 48 | + </div> |
| 49 | + ); |
50 | 50 | }; |
0 commit comments