Skip to content

Commit

Permalink
fix(cb2-13615): ensure we're not showing child if parent is also hidd…
Browse files Browse the repository at this point in the history
…en (#1554)

* fix(cb2-13615): ensure we're not showing child if parent is also hidden

* fix(cb2-13615): fix unit tests

---------

Co-authored-by: Thomas Evans <[email protected]>
  • Loading branch information
pbardy2000 and tomevs88 authored Aug 23, 2024
1 parent 6507b00 commit b8ab7fd
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/app/forms/validators/custom-validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export class CustomValidators {
return (control: AbstractControl): ValidationErrors | null => {
if (control?.parent) {
const siblingControl = control.parent.get(sibling) as CustomFormControl;

siblingControl.meta.hide =
Array.isArray(value) && control.value ? value.includes(control.value) : control.value === value;
}
Expand All @@ -34,7 +33,6 @@ export class CustomValidators {
return (control: AbstractControl): ValidationErrors | null => {
if (control?.parent) {
const siblingControl = control.parent.get(sibling) as CustomFormControl;

siblingControl.meta.hide = Array.isArray(value) ? !value.includes(control.value) : control.value !== value;
}

Expand Down Expand Up @@ -76,7 +74,6 @@ export class CustomValidators {
return (control: AbstractControl): ValidationErrors | null => {
if (control?.parent && control.parent.parent) {
const siblingControl = control.parent.parent.get(parentSibling) as CustomFormControl;

siblingControl.meta.hide = Array.isArray(value) ? !value.includes(control.value) : control.value !== value;
}

Expand All @@ -86,7 +83,9 @@ export class CustomValidators {

static hideIfParentSiblingEquals = (parentSibling: string, value: unknown): ValidatorFn => {
return (control: AbstractControl): ValidationErrors | null => {
if (control?.parent && control.parent.parent) {
if (control && control.parent && control.parent.parent) {
if ((control.parent as CustomFormControl | CustomFormGroup).meta?.hide) return null;
if ((control.parent.parent as CustomFormControl | CustomFormGroup).meta?.hide) return null;
const siblingControl = control.parent.parent.get(parentSibling) as CustomFormControl;
siblingControl.meta.hide =
Array.isArray(value) && control.value ? value.includes(control.value) : control.value === value;
Expand Down

0 comments on commit b8ab7fd

Please sign in to comment.