Skip to content

Commit 4b75fa0

Browse files
committed
fix(Form): 修复search组件报错
1 parent d6a36be commit 4b75fa0

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

example/examples/src/routes/Form/index.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,19 @@ const FormDemo = () => {
7575
},
7676
{
7777
type: 'search',
78-
field: 'search',
79-
name: '搜索',
78+
field: 'project',
79+
required: false,
80+
name: '项目',
8081
options: [
81-
{label: '上海', value: 1},
82-
{label: '南京', value: 2},
82+
{label: '测试系统管理', value: 1},
83+
{label: '后台管理', value: 2},
8384
],
8485
attr: {
85-
labelInValue: true,
8686
showClear: true,
87+
labelInValue: true,
8788
},
89+
placeholder: '请输入',
90+
validate: (val: any) => (!val ? '请输入项目' : ''),
8891
},
8992
{
9093
type: 'stepper',

packages/core/src/Form/formItems.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const FormItems = ({ schema = [] }: Pick<FormProps, 'schema'>) => {
2020

2121
const change = (field: KeyType, value: unknown) => {
2222
updateStore?.({ store: { ...store, [field]: value } });
23-
watch[field]?.(value);
23+
watch && watch[field]?.(value);
2424
};
2525

2626
const _renderComponent = (v: FormItemsProps) => {

packages/core/src/SearchBar/index.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ interface SearchBarProps {
2424
onBlur?: (e: any | string) => void;
2525
labelInValue?: Boolean;
2626
disabled?: Boolean;
27-
value?: String;
27+
value?: string | OptionsState;
2828
loading?: Boolean;
29-
placeholder?: String;
29+
placeholder?: string;
3030
extra?: JSX.Element;
3131
showClear?: boolean;
3232
contentStyle?: StyleProp<ViewStyle>;
@@ -55,16 +55,18 @@ function SearchBar({
5555
}: SearchBarProps) {
5656
const [curValue, setCurValue] = useState<any>(value);
5757
const [visible, setVisivble] = useState(false);
58-
const textValue = labelInValue ? curValue && curValue.label : curValue;
58+
let textValue;
59+
if (labelInValue) {
60+
textValue = curValue?.label;
61+
} else {
62+
const { label }: any = options.find((item) => item.value === curValue);
63+
textValue = label;
64+
}
5965

6066
useEffect(() => {
6167
setCurValue(value);
6268
}, [value]);
6369

64-
// useEffect(() => {
65-
// visible && onFocus;
66-
// }, [visible]);
67-
6870
// 搜索
6971
const onHandleChangeText = (val: string) => {
7072
onChangeText && onChangeText(val);
@@ -134,9 +136,9 @@ function SearchBar({
134136
const selectValue:
135137
| any
136138
| {
137-
key: string;
138-
label: string;
139-
} = labelInValue ? { key: itm.value, label: itm.label } : itm.value;
139+
key: string;
140+
label: string;
141+
} = labelInValue ? { key: itm.value, label: itm.label } : itm.value;
140142
onChange && onChange(selectValue);
141143
setCurValue(selectValue);
142144
setVisivble(false);

0 commit comments

Comments
 (0)