Skip to content

Commit 484ff24

Browse files
authored
Fix for #1775 and #1760 (#1781)
fix two issues on required field validation issues in Dynamic Form Control
1 parent 4eecc00 commit 484ff24

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/controls/dynamicForm/DynamicForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ export class DynamicForm extends React.Component<
354354

355355
// When a field is required and has no value
356356
if (field.required) {
357-
if (field.newValue === null) {
357+
if (field.newValue === undefined && field.value===undefined) {
358358
if (
359359
field.defaultValue === null ||
360360
field.defaultValue === "" ||

src/controls/dynamicForm/dynamicField/DynamicField.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,15 @@ export class DynamicField extends React.Component<IDynamicFieldProps, IDynamicFi
625625
const {
626626
changedValue
627627
} = this.state;
628-
return (changedValue === undefined || changedValue === '' || changedValue === null || this.isEmptyArray(changedValue)) && this.props.required ? strings.DynamicFormRequiredErrorMessage : null;
628+
const {value,newValue,required}=this.props;
629+
if(newValue===undefined){
630+
return required && (changedValue === undefined || changedValue === '' || changedValue === null || this.isEmptyArray(changedValue))
631+
&& (value === undefined || value === '' || value === null || this.isEmptyArray(value))? strings.DynamicFormRequiredErrorMessage : null;
632+
}
633+
else{
634+
return required && (changedValue === undefined || changedValue === '' || changedValue === null || this.isEmptyArray(changedValue)) ? strings.DynamicFormRequiredErrorMessage : null;
635+
}
636+
629637
}
630638

631639
private getNumberErrorText = (): string => {
@@ -637,10 +645,17 @@ export class DynamicField extends React.Component<IDynamicFieldProps, IDynamicFi
637645
fieldType,
638646
maximumValue,
639647
minimumValue,
640-
showAsPercentage
648+
showAsPercentage,
649+
value,
650+
newValue,
651+
required
641652
} = this.props;
642653

643-
if ((changedValue === undefined || changedValue === '' || changedValue === null || this.isEmptyArray(changedValue)) && this.props.required) {
654+
if (required && newValue!==undefined && (changedValue === undefined || changedValue === '' || changedValue === null || this.isEmptyArray(changedValue)) ) {
655+
return strings.DynamicFormRequiredErrorMessage;
656+
}
657+
658+
if (required && newValue===undefined && (value === undefined || value === '' || value === null || this.isEmptyArray(value)) && (changedValue === undefined || changedValue === '' || changedValue === null || this.isEmptyArray(changedValue)) ) {
644659
return strings.DynamicFormRequiredErrorMessage;
645660
}
646661

0 commit comments

Comments
 (0)