Skip to content

Commit 736c3a1

Browse files
committed
fix(ProForm): 调整效验规则
1 parent 40c51f2 commit 736c3a1

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

packages/components/src/ProForm/utils/index.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,15 @@ export const fromValidate = (rules: FromValidateProps[] = []) => {
173173
});
174174
return errorObj;
175175
};
176+
177+
/**
178+
* 判断rules 里面是 required 是否存在
179+
*/
180+
export const isRequired = (rules: any[] = []): boolean => {
181+
if (rules.length === 0) return false;
182+
const requireds = rules.find((item) => item.required) || [];
183+
if (requireds && requireds.length > 0) {
184+
return true;
185+
}
186+
return false;
187+
};

packages/components/src/ProForm/widgets/index.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import CheckBox from './CheckBox';
1515
import SelectMultiple from './SelectMultiple';
1616
import Upload from './Upload';
1717
import SearchTree from './SearchTree';
18+
import { isRequired } from '../utils';
1819

1920
/**
2021
*
@@ -62,12 +63,11 @@ export function getFormFields(
6263
const name = key;
6364
const Widget = widgetsList[widget];
6465
fields[name] = {
65-
label:
66-
otherProps.rules && otherProps.rules.length > 0 ? (
67-
<span className="w-proform-label">{label}</span>
68-
) : (
69-
label
70-
),
66+
label: isRequired(otherProps.rules) ? (
67+
<span className="w-proform-label">{label}</span>
68+
) : (
69+
label
70+
),
7171
children: <Widget {...widgetProps} />,
7272
...otherProps,
7373
initialValue,

0 commit comments

Comments
 (0)