Disabled all form elements that should not be sent to the controller

This commit is contained in:
Jean-Baptiste Bellet
2021-11-26 11:36:06 +01:00
committed by Matt-Yorkley
parent f7662947dc
commit fd5ad7566a
2 changed files with 73 additions and 3 deletions

View File

@@ -10,9 +10,11 @@ export default class extends Controller {
if (e.id === paymentMethodContainerId) {
e.style.display = "block";
this.addRequiredAttributeOnInputIfNeeded(e);
this.removeDisabledAttributeOnInput(e);
} else {
e.style.display = "none";
this.removeRequiredAttributeOnInput(e);
this.addDisabledAttributeOnInput(e);
}
});
}
@@ -20,6 +22,19 @@ export default class extends Controller {
getFormElementsArray(container) {
return Array.from(container.querySelectorAll("input, select, textarea"));
}
addDisabledAttributeOnInput(container) {
this.getFormElementsArray(container).forEach((i) => {
i.disabled = true;
});
}
removeDisabledAttributeOnInput(container) {
this.getFormElementsArray(container).forEach((i) => {
i.disabled = false;
});
}
removeRequiredAttributeOnInput(container) {
this.getFormElementsArray(container).forEach((i) => {
if (i.required) {