From 6a26223f93c3233f7aa96644176edb72c4e4cdc2 Mon Sep 17 00:00:00 2001 From: Gbubemi Smith Date: Wed, 13 Jul 2022 15:14:03 +0100 Subject: [PATCH] Fixed self host defect (#3094) --- libs/angular/src/components/register.component.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libs/angular/src/components/register.component.ts b/libs/angular/src/components/register.component.ts index b07891371b..967cb0e440 100644 --- a/libs/angular/src/components/register.component.ts +++ b/libs/angular/src/components/register.component.ts @@ -1,5 +1,5 @@ import { Directive, EventEmitter, Input, OnInit, Output } from "@angular/core"; -import { FormBuilder, Validators } from "@angular/forms"; +import { AbstractControl, FormBuilder, ValidatorFn, Validators } from "@angular/forms"; import { Router } from "@angular/router"; import { InputsFieldMatch } from "@bitwarden/angular/validators/inputsFieldMatch.validator"; @@ -50,7 +50,7 @@ export class RegisterComponent extends CaptchaProtectedComponent implements OnIn ), ], ], - acceptPolicies: [false, [Validators.requiredTrue]], + acceptPolicies: [false, [this.acceptPoliciesValidation()]], }, { validator: InputsFieldMatch.validateFormInputsMatch( @@ -275,4 +275,13 @@ export class RegisterComponent extends CaptchaProtectedComponent implements OnIn const name = error.errorName.charAt(0).toUpperCase() + error.errorName.slice(1); return `${error.controlName}${name}`; } + + //validation would be ignored on selfhosted + private acceptPoliciesValidation(): ValidatorFn { + return (control: AbstractControl) => { + const ctrlValue = control.value; + + return !ctrlValue && this.showTerms ? { required: true } : null; + }; + } }