Typo fixes for required fields
This commit is contained in:
@@ -30,7 +30,7 @@ export class HandledarePickerFormComponent implements OnChanges {
|
||||
@Input() invalid = false;
|
||||
@Output() selectedHandledareChanged = new EventEmitter<string>();
|
||||
formGroup: FormGroup = new FormGroup({
|
||||
handledare: new FormControl(null, [RequiredValidator('Handledare')]),
|
||||
handledare: new FormControl(null, [RequiredValidator('Handledare är obligatorisk')]),
|
||||
});
|
||||
selectableHandledare: FormSelectItem[] = [];
|
||||
submitted = false;
|
||||
|
||||
@@ -27,7 +27,7 @@ export class OrganizationPickerFormComponent implements OnChanges {
|
||||
@Output() selectedOrganizationChanged = new EventEmitter<Organization>();
|
||||
|
||||
organizationPickerFormGroup: FormGroup = new FormGroup({
|
||||
organization: new FormControl(null, [RequiredValidator('Organisation')]),
|
||||
organization: new FormControl(null, [RequiredValidator('Organisation är obligatorisk')]),
|
||||
});
|
||||
selectableOrganizations: Array<FormSelectItem> = [];
|
||||
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
import { AbstractControl, ValidatorFn } from '@angular/forms';
|
||||
import { ValidationError } from '@msfa-models/validation-error.model';
|
||||
|
||||
export function RequiredValidator(label = 'Fältet', arrayValue = false): ValidatorFn {
|
||||
export function RequiredValidator(message = 'Fältet är obligatoriskt'): ValidatorFn {
|
||||
return (control: AbstractControl): ValidationError => {
|
||||
if (control) {
|
||||
if ((arrayValue && !control.value) || (Array.isArray(control.value) && !control.value.length)) {
|
||||
return { type: 'required', message: `Minst ${label} behöver väljas` };
|
||||
}
|
||||
|
||||
if (!control.value) {
|
||||
return { type: 'required', message: `${label} är obligatoriskt` };
|
||||
if (!control.value || (Array.isArray(control.value) && !control.value.length)) {
|
||||
return { type: 'required', message };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user