AAE-23379 Fix - Required empty attach file field allows user to submi… (#9865)

* AAE-23379 Fix - Required empty attach file field allows user to submit form

* small update
This commit is contained in:
Tomasz Gnyp
2024-06-25 11:59:28 +02:00
committed by GitHub
parent bf5b45e31a
commit fb275d94c0
4 changed files with 60 additions and 4 deletions

View File

@@ -11,6 +11,7 @@
[showCompleteButton]="canCompleteTask()"
[showSaveButton]="canCompleteTask()"
[displayModeConfigurations]="displayModeConfigurations"
[fieldValidators]="fieldValidators"
(formSaved)="onFormSaved($event)"
(formCompleted)="onFormCompleted($event)"
(formError)="onError($event)"

View File

@@ -19,7 +19,7 @@ import { DebugElement, SimpleChange } from '@angular/core';
import { By } from '@angular/platform-browser';
import { of } from 'rxjs';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormModel, FormOutcomeEvent, FormOutcomeModel } from '@alfresco/adf-core';
import { FORM_FIELD_VALIDATORS, FormModel, FormOutcomeEvent, FormOutcomeModel } from '@alfresco/adf-core';
import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module';
import { TaskFormCloudComponent } from './task-form-cloud.component';
import {
@@ -37,6 +37,7 @@ import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { MatProgressSpinnerHarness } from '@angular/material/progress-spinner/testing';
import { DisplayModeService } from '../../../form/services/display-mode.service';
import { FormCloudComponent } from '../../../form/components/form-cloud.component';
import { MockFormFieldValidator } from '../mocks/task-form-cloud.mock';
const taskDetails: TaskDetailsCloudModel = {
appName: 'simple-app',
@@ -280,6 +281,22 @@ describe('TaskFormCloudComponent', () => {
component.ngOnChanges({ taskId: new SimpleChange(null, 'task1', false) });
expect(getTaskSpy).not.toHaveBeenCalled();
});
it('should append additional field validators to the default ones when provided', () => {
const mockFirstCustomFieldValidator = new MockFormFieldValidator();
const mockSecondCustomFieldValidator = new MockFormFieldValidator();
component.fieldValidators = [mockFirstCustomFieldValidator, mockSecondCustomFieldValidator];
fixture.detectChanges();
expect(component.fieldValidators).toEqual([...FORM_FIELD_VALIDATORS, mockFirstCustomFieldValidator, mockSecondCustomFieldValidator]);
});
it('should use default field validators when no additional validators are provided', () => {
fixture.detectChanges();
expect(component.fieldValidators).toEqual([...FORM_FIELD_VALIDATORS]);
});
});
describe('Events', () => {

View File

@@ -18,7 +18,7 @@
import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges, OnInit, ViewEncapsulation, OnDestroy, ViewChild } from '@angular/core';
import { TaskDetailsCloudModel } from '../../start-task/models/task-details-cloud.model';
import { TaskCloudService } from '../../services/task-cloud.service';
import { FormRenderingService, FormModel, ContentLinkModel, FormOutcomeEvent } from '@alfresco/adf-core';
import { FormRenderingService, FormModel, ContentLinkModel, FormOutcomeEvent, FormFieldValidator, FORM_FIELD_VALIDATORS } from '@alfresco/adf-core';
import { AttachFileCloudWidgetComponent } from '../../../form/components/widgets/attach-file/attach-file-cloud-widget.component';
import { DropdownCloudWidgetComponent } from '../../../form/components/widgets/dropdown/dropdown-cloud.widget';
import { DateCloudWidgetComponent } from '../../../form/components/widgets/date/date-cloud.widget';
@@ -72,6 +72,10 @@ export class TaskFormCloudComponent implements OnInit, OnChanges, OnDestroy {
@Input()
displayModeConfigurations: FormCloudDisplayModeConfiguration[];
/** FormFieldValidator allow to provide additional validators to the form field. */
@Input()
fieldValidators: FormFieldValidator[];
/** Emitted when the form is saved. */
@Output()
formSaved = new EventEmitter<FormModel>();
@@ -143,6 +147,8 @@ export class TaskFormCloudComponent implements OnInit, OnChanges, OnDestroy {
}
ngOnInit() {
this.initFieldValidators();
if (this.appName === '' && this.taskId) {
this.loadTask();
}
@@ -162,6 +168,10 @@ export class TaskFormCloudComponent implements OnInit, OnChanges, OnDestroy {
}
}
private initFieldValidators() {
this.fieldValidators = this.fieldValidators ? [...FORM_FIELD_VALIDATORS, ...this.fieldValidators] : [...FORM_FIELD_VALIDATORS];
}
private loadTask() {
this.loading = true;
this.taskCloudService
@@ -254,11 +264,11 @@ export class TaskFormCloudComponent implements OnInit, OnChanges, OnDestroy {
this.adfCloudForm.switchToDisplayMode(newDisplayMode);
}
onDisplayModeOn(displayModeConfiguration: FormCloudDisplayModeConfiguration){
onDisplayModeOn(displayModeConfiguration: FormCloudDisplayModeConfiguration) {
this.displayModeOn.emit(displayModeConfiguration);
}
onDisplayModeOff(displayModeConfiguration: FormCloudDisplayModeConfiguration){
onDisplayModeOff(displayModeConfiguration: FormCloudDisplayModeConfiguration) {
this.displayModeOff.emit(displayModeConfiguration);
}

View File

@@ -0,0 +1,28 @@
/*!
* @license
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { FormFieldModel, FormFieldValidator } from '@alfresco/adf-core';
export class MockFormFieldValidator implements FormFieldValidator {
isSupported(_field: FormFieldModel): boolean {
return true;
}
validate(_field: FormFieldModel): boolean {
return true;
}
}