@@ -206,11 +206,14 @@ export class DynamicForm extends React.Component<
206
206
} else if ( Array . isArray ( val . newValue ) && val . newValue . length === 0 ) {
207
207
val . fieldDefaultValue = null ;
208
208
shouldBeReturnBack = true ;
209
+ } else if ( val . fieldType === "Number" ) {
210
+ shouldBeReturnBack = this . validateNumberOnSubmit ( val ) ;
211
+ }
212
+ } else if ( val . fieldType === "Number" ) {
213
+ if ( val . newValue === null ) {
214
+ val . newValue = val . fieldDefaultValue ;
209
215
}
210
- } else if ( val . fieldType === "Number" ) {
211
- if ( ( val . newValue < val . minimumValue ) || ( val . newValue > val . maximumValue ) ) {
212
- shouldBeReturnBack = true ;
213
- }
216
+ shouldBeReturnBack = this . validateNumberOnSubmit ( val ) ;
214
217
}
215
218
} ) ;
216
219
if ( shouldBeReturnBack ) {
@@ -848,4 +851,20 @@ export class DynamicForm extends React.Component<
848
851
849
852
return errorMessage ;
850
853
} ;
854
+
855
+ private validateNumberOnSubmit = ( val :IDynamicFieldProps ) : boolean => {
856
+ let shouldBeReturnBack = false ;
857
+ if ( val . fieldType === "Number" && val . showAsPercentage ) {
858
+ const minValue = val . minimumValue !== undefined ? val . minimumValue * 100 : undefined ;
859
+ const maxValue = val . maximumValue !== undefined ? val . maximumValue * 100 : undefined ;
860
+ if ( ( val . newValue < minValue ) || ( val . newValue > maxValue ) ) {
861
+ shouldBeReturnBack = true ;
862
+ }
863
+ } else if ( val . fieldType === "Number" && ! val . showAsPercentage ) {
864
+ if ( ( val . newValue < val . minimumValue ) || ( val . newValue > val . maximumValue ) ) {
865
+ shouldBeReturnBack = true ;
866
+ }
867
+ }
868
+ return shouldBeReturnBack ;
869
+ }
851
870
}
0 commit comments