Fixed issues with form validation messages and some styling fixes

This commit is contained in:
Erik Tiekstra
2021-10-11 12:07:23 +02:00
parent 8bcd591a08
commit 0e766ccad2
18 changed files with 214 additions and 291 deletions

View File

@@ -1,4 +1,3 @@
export interface ValidationError {
type: string;
message: string;
[key: string]: string;
}

View File

@@ -12,7 +12,7 @@ export function isoDateWithoutTimeValidator(): ValidatorFn {
const value: string = control.value as string;
if (!isoDateIsValid(value)) {
return { type: 'invalid', message: `Ogiltigt datum, vänligen ange YYYY-MM-DD` };
return { invalid: `Ogiltigt datum, vänligen ange YYYY-MM-DD` };
}
}

View File

@@ -12,7 +12,7 @@ export function EmailValidator(label = 'Fältet'): ValidatorFn {
const value: string = control.value as string;
if (!emailIsValid(value)) {
return { type: 'invalid', message: `Ogiltig ${label}` };
return { invalid: `Ogiltig ${label}` };
}
}
@@ -38,7 +38,7 @@ export function CommaSeparatedEmailValidator(): ValidatorFn {
if (invalidEmailaddresses.length) {
const messagePrepend =
invalidEmailaddresses.length > 1 ? 'Ogiltiga e-postadresser: ' : 'Ogiltig e-postadress: ';
return { type: 'invalid', message: `${messagePrepend}${invalidEmailaddresses.join(', ')}` };
return { invalid: `${messagePrepend}${invalidEmailaddresses.join(', ')}` };
}
}

View File

@@ -5,7 +5,7 @@ export function RequiredValidator(message = 'Fältet är obligatoriskt'): Valida
return (control: AbstractControl): ValidationError => {
if (control) {
if (!control.value || (Array.isArray(control.value) && !control.value.length)) {
return { type: 'required', message };
return { required: message };
}
}

View File

@@ -10,7 +10,7 @@ export function SocialSecurityNumberValidator(): ValidatorFn {
const ssn = control.value as string;
if (/[^0-9-]/g.test(ssn)) {
return { type: 'ssnInvalid', message: 'Inkorrekt personnummer' };
return { ssnInvalid: 'Inkorrekt personnummer' };
}
let strippedSsn = ssn.replace(/[^0-9]/g, '');
@@ -22,12 +22,12 @@ export function SocialSecurityNumberValidator(): ValidatorFn {
// Check length
if (strippedSsn.length !== 10) {
return { type: 'ssnNotComplete', message: 'Personnummret är inte fullständigt' };
return { ssnNotComplete: 'Personnummret är inte fullständigt' };
}
// Check month
if (+strippedSsn.substr(2, 2) > 12 || strippedSsn.substr(2, 2) === '00') {
return { type: 'ssnInvalid', message: 'Inkorrekt personnummer' };
return { ssnInvalid: 'Inkorrekt personnummer' };
}
// Check date (valid date + 60 is also apporved because of co-ordination number)
@@ -35,10 +35,10 @@ export function SocialSecurityNumberValidator(): ValidatorFn {
(+strippedSsn.substr(4, 2) > 31 || strippedSsn.substr(4, 2) === '00') &&
(+strippedSsn.substr(4, 2) > 91 || +strippedSsn.substr(4, 2) <= 60)
) {
return { type: 'ssnInvalid', message: 'Inkorrekt personnummer' };
return { ssnInvalid: 'Inkorrekt personnummer' };
}
return isControlDigitLegit(strippedSsn) ? null : { type: 'ssnInvalid', message: 'Inkorrekt personnummer' };
return isControlDigitLegit(strippedSsn) ? null : { ssnInvalid: 'Inkorrekt personnummer' };
};
}