Skip to content

Commit

Permalink
Fix visa disabling process: now visa validates only current title lev…
Browse files Browse the repository at this point in the history
…el 1
  • Loading branch information
maatinito committed Oct 25, 2023
1 parent 6aa0126 commit 087b9ad
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions app/javascript/controllers/visa_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,38 @@ export class VisaController extends ApplicationController {
private updateVisibilityOfAboveFields(visa: HTMLInputElement) {
if (visa == null) return;

let champ: Element | null | undefined;
champ = visa.closest(VisaController.CHAMP_SELECTOR);
while ((champ = champ?.previousElementSibling) != null) {
this.updateVisibility(champ, visa.checked);
let element: Element | null | undefined;
element = visa.closest(VisaController.CHAMP_SELECTOR);
while ((element = element?.previousElementSibling) != null) {
if (this.isTitle(element)) {
if (this.isSubTitle(element)) {
element = element.parentElement;
}
} else {
// champ
this.updateVisibility(element, visa.checked);

if (
!visa.checked &&
champ.classList.contains(VisaController.REPETITION)
) {
this.updateVisibilityOfRepetition(champ);
} else if (this.checked_visa(champ)) {
break;
if (!visa.checked && this.isRepetition(element)) {
this.updateVisibilityOfRepetition(element);
} else if (this.checked_visa(element)) {
break;
}
}
}
}

private isTitle(element: Element) {
return element.tagName === 'LEGEND';
}

private isSubTitle(champ: Element) {
return champ.children.length > 0 && champ.children[0].tagName !== 'H2';
}

private isRepetition(champ: Element) {
return champ.classList.contains(VisaController.REPETITION);
}

private updateVisibilityOfRepetition(champ: Element) {
champ
.querySelectorAll<HTMLInputElement>(VisaController.CHECKED_VISA_SELECTOR)
Expand Down

0 comments on commit 087b9ad

Please sign in to comment.