File tree Expand file tree Collapse file tree 2 files changed +18
-6
lines changed
packages/components/src/ProForm Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Original file line number Diff line number Diff 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+ } ;
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import CheckBox from './CheckBox';
1515import SelectMultiple from './SelectMultiple' ;
1616import Upload from './Upload' ;
1717import 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,
You can’t perform that action at this time.
0 commit comments