Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Aug 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading