From 933a7256a3cb262c0197ae2e68631d6155560022 Mon Sep 17 00:00:00 2001 From: Silviu Popa Date: Tue, 5 Mar 2019 14:37:18 +0200 Subject: [PATCH] [ADF-4068] ProcessServices - add description validation on Edit Task Form (#4366) * [ADF-4068] StartTaskComponent - fix name and description empty space validation * [ADF-4068] StartTakComponent - add unit test * [ADF-4068] ProcessServices - add description validaton on edit task form * [ADF-4068] ProcessServies - fix build issue --- .../src/lib/i18n/en.json | 3 ++ .../components/task-header.component.ts | 4 ++- .../validators/task-description.validator.ts | 29 +++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 lib/process-services/task-list/validators/task-description.validator.ts diff --git a/lib/process-services-cloud/src/lib/i18n/en.json b/lib/process-services-cloud/src/lib/i18n/en.json index 01a53d480e..a3bdb851f0 100644 --- a/lib/process-services-cloud/src/lib/i18n/en.json +++ b/lib/process-services-cloud/src/lib/i18n/en.json @@ -200,6 +200,9 @@ "DESCRIPTION_DEFAULT": "No description", "FORM_NAME": "Form Name", "FORM_NAME_DEFAULT": "No form" + }, + "FORM_VALIDATION": { + "INVALID_FIELD": "Enter a different value" } } } diff --git a/lib/process-services/task-list/components/task-header.component.ts b/lib/process-services/task-list/components/task-header.component.ts index 140edaa5b8..1795c895b8 100644 --- a/lib/process-services/task-list/components/task-header.component.ts +++ b/lib/process-services/task-list/components/task-header.component.ts @@ -29,6 +29,7 @@ import { } from '@alfresco/adf-core'; import { TaskDetailsModel } from '../models/task-details.model'; import { TaskListService } from './../services/tasklist.service'; +import { TaskDescriptionValidator } from '../validators/task-description.validator'; @Component({ selector: 'adf-task-header', @@ -168,7 +169,8 @@ export class TaskHeaderComponent implements OnChanges, OnInit { key: 'description', default: this.translationService.instant('ADF_TASK_LIST.PROPERTIES.DESCRIPTION_DEFAULT'), multiline: true, - editable: true + editable: true, + validators: [new TaskDescriptionValidator()] } ), new CardViewTextItemModel( diff --git a/lib/process-services/task-list/validators/task-description.validator.ts b/lib/process-services/task-list/validators/task-description.validator.ts new file mode 100644 index 0000000000..43bc5f0c6f --- /dev/null +++ b/lib/process-services/task-list/validators/task-description.validator.ts @@ -0,0 +1,29 @@ +/*! + * @license + * Copyright 2019 Alfresco Software, Ltd. + * + * 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 { CardViewItemValidator } from '@alfresco/adf-core'; + +export class TaskDescriptionValidator implements CardViewItemValidator { + + message: string = 'ADF_CLOUD_TASK_HEADER.FORM_VALIDATION.INVALID_FIELD'; + + isValid(value: any): boolean { + const isWhitespace = (value || '').trim().length === 0; + return value.length === 0 || !isWhitespace; + } + +}