@@ -95,7 +95,6 @@ export class DynamicField extends React.Component<IDynamicFieldProps, IDynamicFi
9595
9696 const labelEl = < label className = { ( required ) ? styles . fieldRequired + ' ' + styles . fieldLabel : styles . fieldLabel } > { labelText } </ label > ;
9797 const errorText = this . getRequiredErrorText ( ) ;
98- const errorTextforNumber = this . getNumberErrorText ( ) ;
9998 const errorTextEl = < text className = { styles . errormessage } > { errorText } </ text > ;
10099 const descriptionEl = < text className = { styles . fieldDescription } > { description } </ text > ;
101100 const hasImage = ! ! changedValue ;
@@ -213,6 +212,7 @@ export class DynamicField extends React.Component<IDynamicFieldProps, IDynamicFi
213212 </ div > ;
214213
215214 case 'Lookup' :
215+ //eslint-disable-next-line no-case-declarations
216216 const lookupValue = this . props . newValue ? this . props . newValue : defaultValue ;
217217 return < div >
218218 < div className = { styles . titleContainer } >
@@ -236,6 +236,7 @@ export class DynamicField extends React.Component<IDynamicFieldProps, IDynamicFi
236236 </ div > ;
237237
238238 case 'LookupMulti' :
239+ //eslint-disable-next-line no-case-declarations
239240 const lookupMultiValue = this . props . newValue ? this . props . newValue : defaultValue ;
240241 return < div >
241242 < div className = { styles . titleContainer } >
@@ -259,6 +260,9 @@ export class DynamicField extends React.Component<IDynamicFieldProps, IDynamicFi
259260 </ div > ;
260261
261262 case 'Number' :
263+ //eslint-disable-next-line no-case-declarations
264+ const customNumberErrorMessage = this . getNumberErrorText ( ) ;
265+
262266 return < div >
263267 < div className = { styles . titleContainer } >
264268 < Icon className = { styles . fieldIcon } iconName = { "NumberField" } />
@@ -272,7 +276,7 @@ export class DynamicField extends React.Component<IDynamicFieldProps, IDynamicFi
272276 onChange = { ( e , newText ) => { this . onChange ( newText ) ; } }
273277 disabled = { disabled }
274278 onBlur = { this . onBlur }
275- errorMessage = { errorTextforNumber } />
279+ errorMessage = { customNumberErrorMessage } />
276280 { descriptionEl }
277281 </ div > ;
278282
@@ -601,17 +605,34 @@ export class DynamicField extends React.Component<IDynamicFieldProps, IDynamicFi
601605 showAsPercentage
602606 } = this . props ;
603607
604- let errorText : string | null = null ;
608+ if ( ( changedValue === undefined || changedValue === '' || changedValue === null || this . isEmptyArray ( changedValue ) ) && this . props . required ) {
609+ return strings . DynamicFormRequiredErrorMessage ;
610+ }
611+
612+ let minValue = minimumValue !== undefined && minimumValue !== - ( Number . MAX_VALUE ) ? minimumValue : undefined ;
613+ let maxValue = maximumValue !== undefined && maximumValue !== Number . MAX_VALUE ? maximumValue : undefined ;
605614
606- errorText = this . getRequiredErrorText ( ) ;
607- if ( ! errorText && ( changedValue < minimumValue ) || ( changedValue > maximumValue ) ) {
608- if ( ! showAsPercentage ) {
609- errorText = strings . DynamicFormNumberErrorMessage
610- . replace ( '{0}' , minimumValue . toString ( ) )
611- . replace ( '{1}' , maximumValue . toString ( ) ) ;
615+ if ( showAsPercentage === true ) {
616+ // In case of percentage we need to convert the min and max values to a percentage value
617+ minValue = minValue !== undefined ? minValue * 100 : undefined ;
618+ maxValue = maxValue !== undefined ? maxValue * 100 : undefined ;
619+ }
620+
621+ if ( changedValue !== undefined && changedValue !== null && changedValue . length > 0 ) {
622+ if ( minValue !== undefined && maxValue !== undefined && ( changedValue < minValue || changedValue > maxValue ) ) {
623+ return strings . DynamicFormNumberValueMustBeBetween . replace ( '{0}' , minValue . toString ( ) ) . replace ( '{1}' , maxValue . toString ( ) ) ;
624+ }
625+ else {
626+ if ( minValue !== undefined && changedValue < minValue ) {
627+ return strings . DynamicFormNumberValueMustBeGreaterThan . replace ( '{0}' , minValue . toString ( ) ) ;
628+ }
629+ else if ( maxValue !== undefined && changedValue > maxValue ) {
630+ return strings . DynamicFormNumberValueMustBeLowerThan . replace ( '{0}' , maxValue . toString ( ) ) ;
631+ }
612632 }
613633 }
614- return errorText ;
634+
635+ return null ;
615636 }
616637
617638 private isEmptyArray ( value ) : boolean {
0 commit comments