Skip to content

Commit

Permalink
Merge pull request #207 from yaob421123/master
Browse files Browse the repository at this point in the history
fix(ProForm): 调整效验规则
  • Loading branch information
ChenlingasMx authored Apr 8, 2023
2 parents 40c51f2 + 736c3a1 commit dd933da
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 12 additions & 0 deletions packages/components/src/ProForm/utils/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,15 @@ export const fromValidate = (rules: FromValidateProps[] = []) => {
});
return errorObj;
};

/**
* 判断rules 里面是 required 是否存在
*/
export const isRequired = (rules: any[] = []): boolean => {
if (rules.length === 0) return false;
const requireds = rules.find((item) => item.required) || [];
if (requireds && requireds.length > 0) {
return true;
}
return false;
};
12 changes: 6 additions & 6 deletions packages/components/src/ProForm/widgets/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import CheckBox from './CheckBox';
import SelectMultiple from './SelectMultiple';
import Upload from './Upload';
import SearchTree from './SearchTree';
import { isRequired } from '../utils';

/**
*
Expand Down Expand Up @@ -62,12 +63,11 @@ export function getFormFields(
const name = key;
const Widget = widgetsList[widget];
fields[name] = {
label:
otherProps.rules && otherProps.rules.length > 0 ? (
<span className="w-proform-label">{label}</span>
) : (
label
),
label: isRequired(otherProps.rules) ? (
<span className="w-proform-label">{label}</span>
) : (
label
),
children: <Widget {...widgetProps} />,
...otherProps,
initialValue,
Expand Down

0 comments on commit dd933da

Please sign in to comment.