From f8a2bce09c804e23ef172105ca17f91e56a5e257 Mon Sep 17 00:00:00 2001 From: Pete Muir Date: Thu, 16 Mar 2017 07:49:04 -0400 Subject: [PATCH] fix(spaces): provide more validation error info Encapsulation FTW! --- src/app/spaces/valid-space-name.directive.ts | 24 +++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/app/spaces/valid-space-name.directive.ts b/src/app/spaces/valid-space-name.directive.ts index a09c8f8..cb11bc2 100644 --- a/src/app/spaces/valid-space-name.directive.ts +++ b/src/app/spaces/valid-space-name.directive.ts @@ -57,13 +57,31 @@ export function validSpaceNameValidator(): AsyncValidatorFn { .takeUntil(changed$) .map(value => { if (!control.value || control.value.toString().length > ValidSpaceNameValidatorDirective.MAX_SPACE_NAME_LENGTH) { - return { maxLength: { valid: false, requestedName: control.value } }; + return { + maxLength: { + valid: false, + requestedName: control.value, + max: ValidSpaceNameValidatorDirective.MAX_SPACE_NAME_LENGTH, + } + }; } let strVal: string = control.value.toString(); if (strVal.length < ValidSpaceNameValidatorDirective.MIN_SPACE_NAME_LENGTH) { - return { minLength: { valid: false, requestedName: control.value } }; + return { + minLength: { + valid: false, + requestedName: control.value, + min: ValidSpaceNameValidatorDirective.MIN_SPACE_NAME_LENGTH + } + }; } else if (!strVal.match(ValidSpaceNameValidatorDirective.ALLOWED_SPACE_NAMES)) { - return { invalid: { valid: false, requestedName: control.value } }; + return { + invalid: { + valid: false, + requestedName: control.value, + allowedChars: ValidSpaceNameValidatorDirective.ALLOWED_SPACE_NAMES + } + }; } return null; })