Skip to content

Commit

Permalink
IKC-414 Cluster name validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Belke authored and Piotr Belke committed Sep 30, 2024
1 parent 02a45ad commit ea7da8d
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
FormControl,
FormGroup,
ValidationErrors,
ValidatorFn,
Validators
} from '@angular/forms';
import {ClusterService} from './cluster.service';
Expand Down Expand Up @@ -99,7 +100,7 @@ export class ClusterFormComponent implements OnInit, OnDestroy, AfterViewInit {
clusterForm: FormGroup = new FormGroup({
id: new FormControl(),
name: new FormControl('', {
validators: [Validators.required],
validators: [Validators.required, this.noWhitespaces()],
asyncValidators: this.nameShouldBeUnique(),
updateOn: 'change'
}),
Expand Down Expand Up @@ -198,6 +199,7 @@ export class ClusterFormComponent implements OnInit, OnDestroy, AfterViewInit {
this.navigateToList();
}));
} else {
this.model.name = this.model.name.trim();
this.subscriptions.add(this.clusterService.addNewCluster$(this.model).subscribe(() => {
this.navigateToList();
}));
Expand Down Expand Up @@ -234,4 +236,10 @@ export class ClusterFormComponent implements OnInit, OnDestroy, AfterViewInit {
}));
};
}

noWhitespaces(): ValidatorFn {
return (control: AbstractControl): ValidationErrors | null => {
return control.value.length === 0 || (control.value || '').trim().length ? null : {incorrectValue: true};
};
}
}

0 comments on commit ea7da8d

Please sign in to comment.