[ADF-4068] StartTaskComponent - fix name and description empty space … (#4351)

* [ADF-4068] StartTaskComponent - fix name and description empty space validation

* [ADF-4068] StartTakComponent - add unit test
This commit is contained in:
Silviu Popa
2019-02-25 21:53:20 +02:00
committed by Eugenio Romano
parent 71dca95749
commit 0aaa6bea16
4 changed files with 34 additions and 11 deletions

View File

@@ -102,14 +102,22 @@ export class StartTaskComponent implements OnInit {
buildForm() {
this.taskForm = this.formBuilder.group({
name: new FormControl(this.taskDetailsModel.name, [Validators.required, Validators.maxLength(this.maxTaskNameLength)]),
description: new FormControl(''),
name: new FormControl(this.taskDetailsModel.name, [Validators.required, Validators.maxLength(this.maxTaskNameLength), this.whitespaceValidator]),
description: new FormControl('', [this.whitespaceValidator]),
formKey: new FormControl('')
});
this.taskForm.valueChanges.subscribe((taskFormValues) => this.setTaskDetails(taskFormValues));
}
public whitespaceValidator(control: FormControl) {
if (control.value) {
const isWhitespace = (control.value || '').trim().length === 0;
const isValid = control.value.length === 0 || !isWhitespace;
return isValid ? null : { 'whitespace': true };
}
}
setTaskDetails(form) {
this.taskDetailsModel.name = form.name;
this.taskDetailsModel.description = form.description;