Skip to content

Commit d856296

Browse files
committed
fix(fr):修复setSchema&表单联动&Select组件的bug
1 parent b59e373 commit d856296

5 files changed

Lines changed: 83 additions & 13 deletions

File tree

packages/form-render/src/form-render-core/src/createWidget.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export const transformProps = props => {
4848
onChange(newValue);
4949
};
5050
if (trigger && typeof trigger === 'string') {
51+
controlProps.onChange = _onChange;
5152
controlProps[trigger] = _onChange;
5253
} else {
5354
controlProps.onChange = _onChange;

packages/form-render/src/form-render-core/src/useForm.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,12 @@ const useForm = props => {
229229
// ]
230230

231231
const syncStuff = ({
232-
schema,
233-
locale,
234-
validateMessages,
235-
beforeFinish,
236-
removeHiddenData,
237-
}) => {
232+
schema,
233+
locale,
234+
validateMessages,
235+
beforeFinish,
236+
removeHiddenData,
237+
}) => {
238238
schemaRef.current = schema;
239239
localeRef.current = locale;
240240
validateMessagesRef.current = validateMessages;
@@ -315,7 +315,11 @@ const useForm = props => {
315315
let newError = _errorFields.current.filter(item => {
316316
return item.name.indexOf(path) === -1;
317317
});
318-
setState({ outErrorFields: newError });
318+
319+
let newOutError = _outErrorFields.current.filter(item => {
320+
return item.name.indexOf(path) === -1;
321+
});
322+
setState({ errorFields: newError, outErrorFields: newOutError });
319323
};
320324

321325
const getValues = () => {

packages/form-render/src/index.d.ts

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,51 @@
11
import * as React from 'react';
2-
import Schema from './schema';
2+
import { RuleItem } from 'async-validator';
33

4-
export { Schema };
4+
interface SchemaBase {
5+
type: 'string' | 'number' | 'boolean' | 'array' | 'object' | 'range' | 'html';
6+
title: string;
7+
description: string;
8+
descType: 'text' | 'icon';
9+
format:
10+
| 'image'
11+
| 'textarea'
12+
| 'color'
13+
| 'email'
14+
| 'url'
15+
| 'dateTime'
16+
| 'date'
17+
| 'time'
18+
| 'upload';
19+
default: any;
20+
/** 是否必填,支持 `'{{ formData.xxx === "" }}'` 形式的表达式 */
21+
required: boolean | string;
22+
placeholder: string;
23+
bind: false | string | string[];
24+
dependencies: string[];
25+
min: number;
26+
max: number;
27+
/** 是否禁用,支持 `'{{ formData.xxx === "" }}'` 形式的表达式 */
28+
disabled: boolean | string;
29+
/** 是否只读,支持 `'{{ formData.xxx === "" }}'` 形式的表达式 */
30+
readOnly: boolean | string;
31+
/** 是否隐藏,隐藏的字段不会在 formData 里透出,支持 `'{{ formData.xxx === "" }}'` 形式的表达式 */
32+
hidden: boolean | string;
33+
displayType: 'row' | 'column';
34+
width: string;
35+
labelWidth: number | string;
36+
className: string;
37+
widget: string;
38+
readOnlyWidget: string;
39+
extra: string;
40+
properties: Record<string, Schema>;
41+
items: Schema;
42+
enum: Array<string | number>;
43+
enumNames: Array<string | number>;
44+
rules: RuleItem | RuleItem[];
45+
props: Record<string, any>;
46+
}
47+
48+
type Schema = Partial<SchemaBase>;
549

650
export interface Error {
751
/** 错误的数据路径 */

packages/form-render/src/schema.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,6 @@ interface SchemaBase {
4646

4747
type Schema = Partial<SchemaBase>;
4848

49-
export default Schema;
49+
export = Schema;
50+
51+
export as namespace ISchema;

packages/form-render/src/widgets/antd/select.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
import React from 'react';
1+
import React, { useMemo } from 'react';
22
import { Select } from 'antd';
33
import { getArray } from '../../utils';
4+
import { isUndefined } from 'lodash-es';
45

5-
const FrSelect = ({ schema, style, options: _options, ...rest }) => {
6+
const FrSelect = ({
7+
schema,
8+
style,
9+
value,
10+
onChange,
11+
options: _options,
12+
...rest
13+
}) => {
614
let options;
15+
716
// 如果已经有外部注入的options了,内部的schema就会被忽略
817
if (_options && Array.isArray(_options)) {
918
options = _options;
@@ -19,12 +28,22 @@ const FrSelect = ({ schema, style, options: _options, ...rest }) => {
1928
});
2029
}
2130

31+
const handleChange = val => {
32+
let _val = !isUndefined(val) ? val : null;
33+
onChange(_val);
34+
};
35+
2236
const finalProps = {
2337
options,
2438
style: { width: '100%', ...style },
39+
onChange: handleChange,
2540
...rest,
2641
};
27-
return <Select {...finalProps} />;
42+
return (
43+
<>
44+
<Select defaultValue={value} {...finalProps} />
45+
</>
46+
);
2847
};
2948

3049
export default FrSelect;

0 commit comments

Comments
 (0)