Skip to content

Commit aa19bbd

Browse files
authored
Merge pull request #1490 from smarterbusiness/bugfix/dynamicform-fix-required-multi-fields
DynamicForm - Fixing Required Multi Field Saving Problem
2 parents ce45298 + 34a95e4 commit aa19bbd

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/controls/dynamicForm/DynamicForm.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
104104
}
105105

106106
//trigger when the user submits the form.
107-
private onSubmitClick = async (): Promise<void> => {
107+
private onSubmitClick = async (): Promise<void> => {
108108
const {
109109
listId,
110110
listItemId,
@@ -132,6 +132,10 @@ export class DynamicForm extends React.Component<IDynamicFormProps, IDynamicForm
132132
val.fieldDefaultValue = '';
133133
shouldBeReturnBack = true;
134134
}
135+
else if (Array.isArray(val.newValue) && val.newValue.length === 0) {
136+
val.fieldDefaultValue = null;
137+
shouldBeReturnBack = true;
138+
}
135139
}
136140
});
137141
if (shouldBeReturnBack) {

src/controls/dynamicForm/dynamicField/DynamicField.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ export class DynamicField extends React.Component<IDynamicFieldProps, IDynamicFi
3232
spfxContext: { pageContext: this.props.context.pageContext }
3333
});
3434
this.state = {
35-
changedValue: props.fieldDefaultValue
35+
changedValue: props.fieldType === 'Thumbnail' ? props.fieldDefaultValue : null
3636
};
3737
}
3838

3939
public componentDidUpdate(): void {
40-
if (this.props.fieldDefaultValue === "" && this.state.changedValue === null) {
40+
if ((this.props.fieldDefaultValue === "" || this.props.fieldDefaultValue === null) && this.state.changedValue === null) {
4141
this.setState({ changedValue: "" });
4242
}
4343
}
@@ -585,7 +585,11 @@ export class DynamicField extends React.Component<IDynamicFieldProps, IDynamicFi
585585
const {
586586
changedValue
587587
} = this.state;
588-
return (changedValue === undefined || changedValue === '') && this.props.required ? strings.DynamicFormRequiredErrorMessage : null;
588+
return (changedValue === undefined || changedValue === '' || this.isEmptyArray(changedValue)) && this.props.required ? strings.DynamicFormRequiredErrorMessage : null;
589+
}
590+
591+
private isEmptyArray(value) {
592+
return Array.isArray(value) && value.length === 0;
589593
}
590594

591595
private MultiChoice_selection = (event: React.FormEvent<HTMLDivElement>, item: IDropdownOption): void => {

0 commit comments

Comments
 (0)