Merge pull request #5257 from ArtemDzhereleiko/bug-fix/input-widget/enter-key-press

[3.2.2] Fixed multiple input widget sending double requests and saving required input by Enter keypress
This commit is contained in:
Igor Kulikov 2021-09-27 12:10:23 +03:00 committed by GitHub
commit 4af74071bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -108,7 +108,7 @@
</div> </div>
</fieldset> </fieldset>
<div class="mat-padding" fxLayout="row" fxLayoutAlign="end center" <div class="mat-padding" fxLayout="row" fxLayoutAlign="end center"
*ngIf="entityDetected && settings.showActionButtons"> [fxShow]="entityDetected && settings.showActionButtons">
<button mat-button color="primary" type="button" <button mat-button color="primary" type="button"
(click)="discardAll()" style="max-height: 50px; margin-right:20px;" (click)="discardAll()" style="max-height: 50px; margin-right:20px;"
[disabled]="!multipleInputFormGroup.dirty"> [disabled]="!multipleInputFormGroup.dirty">

View File

@ -109,6 +109,7 @@ export class MultipleInputWidgetComponent extends PageComponent implements OnIni
private datasources: Array<Datasource>; private datasources: Array<Datasource>;
private destroy$ = new Subject(); private destroy$ = new Subject();
public sources: Array<MultipleInputWidgetSource> = []; public sources: Array<MultipleInputWidgetSource> = [];
private isSavingInProgress = false;
isVerticalAlignment: boolean; isVerticalAlignment: boolean;
inputWidthSettings: string; inputWidthSettings: string;
@ -468,7 +469,8 @@ export class MultipleInputWidgetComponent extends PageComponent implements OnIni
} }
public inputChanged(source: MultipleInputWidgetSource, key: MultipleInputWidgetDataKey) { public inputChanged(source: MultipleInputWidgetSource, key: MultipleInputWidgetDataKey) {
if (!this.settings.showActionButtons) { if (!this.settings.showActionButtons && !this.isSavingInProgress) {
this.isSavingInProgress = true;
const currentValue = this.multipleInputFormGroup.get(key.formId).value; const currentValue = this.multipleInputFormGroup.get(key.formId).value;
if (!key.settings.required || (key.settings.required && isDefined(currentValue))) { if (!key.settings.required || (key.settings.required && isDefined(currentValue))) {
const dataToSave: MultipleInputWidgetSource = { const dataToSave: MultipleInputWidgetSource = {
@ -481,7 +483,8 @@ export class MultipleInputWidgetComponent extends PageComponent implements OnIni
} }
public save(dataToSave?: MultipleInputWidgetSource) { public save(dataToSave?: MultipleInputWidgetSource) {
if (document && document.activeElement) { if (document?.activeElement && !this.isSavingInProgress) {
this.isSavingInProgress = true;
(document.activeElement as HTMLElement).blur(); (document.activeElement as HTMLElement).blur();
} }
const config: RequestConfig = { const config: RequestConfig = {
@ -571,12 +574,14 @@ export class MultipleInputWidgetComponent extends PageComponent implements OnIni
() => { () => {
this.multipleInputFormGroup.markAsPristine(); this.multipleInputFormGroup.markAsPristine();
this.ctx.detectChanges(); this.ctx.detectChanges();
this.isSavingInProgress = false;
if (this.settings.showResultMessage) { if (this.settings.showResultMessage) {
this.ctx.showSuccessToast(this.translate.instant('widgets.input-widgets.update-successful'), this.ctx.showSuccessToast(this.translate.instant('widgets.input-widgets.update-successful'),
1000, 'bottom', 'left', this.toastTargetId); 1000, 'bottom', 'left', this.toastTargetId);
} }
}, },
() => { () => {
this.isSavingInProgress = false;
if (this.settings.showResultMessage) { if (this.settings.showResultMessage) {
this.ctx.showErrorToast(this.translate.instant('widgets.input-widgets.update-failed'), this.ctx.showErrorToast(this.translate.instant('widgets.input-widgets.update-failed'),
'bottom', 'left', this.toastTargetId); 'bottom', 'left', this.toastTargetId);
@ -585,6 +590,7 @@ export class MultipleInputWidgetComponent extends PageComponent implements OnIni
} else { } else {
this.multipleInputFormGroup.markAsPristine(); this.multipleInputFormGroup.markAsPristine();
this.ctx.detectChanges(); this.ctx.detectChanges();
this.isSavingInProgress = false;
} }
} }