Check that target exists before setting properties

In case of Xero reports, there are no checkbox
This commit is contained in:
Jean-Baptiste Bellet
2022-11-10 09:49:57 +01:00
parent bdf132a833
commit 4f265eed2a

View File

@@ -10,14 +10,22 @@ export default class extends Controller {
}
disableField() {
this.checkboxTarget.checked = false;
this.checkboxTarget.disabled = true;
this.labelTarget.classList.add("disabled");
if (this.hasCheckboxTarget) {
this.checkboxTarget.checked = false;
this.checkboxTarget.disabled = true;
}
if (this.hasLabelTarget) {
this.labelTarget.classList.add("disabled");
}
}
enableField() {
this.checkboxTarget.checked = true;
this.checkboxTarget.disabled = false;
this.labelTarget.classList.remove("disabled");
if (this.hasCheckboxTarget) {
this.checkboxTarget.checked = true;
this.checkboxTarget.disabled = false;
}
if (this.hasLabelTarget) {
this.labelTarget.classList.remove("disabled");
}
}
}