From b4dab46cf8cd40b9f38d85a22e8a4f61dc9abbf8 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Mon, 20 Dec 2021 17:29:36 +0000 Subject: [PATCH] Remove unused code for changing required attributes --- .../controllers/paymentmethod_controller.js | 19 ---------- .../stimulus/paymentmethod_controller_test.js | 37 +------------------ 2 files changed, 2 insertions(+), 54 deletions(-) diff --git a/app/webpacker/controllers/paymentmethod_controller.js b/app/webpacker/controllers/paymentmethod_controller.js index 94189e3f27..833bfb2c28 100644 --- a/app/webpacker/controllers/paymentmethod_controller.js +++ b/app/webpacker/controllers/paymentmethod_controller.js @@ -29,11 +29,9 @@ export default class extends Controller { ).forEach((e) => { 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); } }); @@ -54,21 +52,4 @@ export default class extends Controller { i.disabled = false; }); } - - removeRequiredAttributeOnInput(container) { - this.getFormElementsArray(container).forEach((i) => { - if (i.required) { - i.dataset.required = i.required; - i.required = false; - } - }); - } - - addRequiredAttributeOnInputIfNeeded(container) { - this.getFormElementsArray(container).forEach((i) => { - if (i.dataset.required === "true") { - i.required = true; - } - }); - } } diff --git a/spec/javascripts/stimulus/paymentmethod_controller_test.js b/spec/javascripts/stimulus/paymentmethod_controller_test.js index a82fdc53c0..09180ac066 100644 --- a/spec/javascripts/stimulus/paymentmethod_controller_test.js +++ b/spec/javascripts/stimulus/paymentmethod_controller_test.js @@ -14,13 +14,13 @@ describe("PaymentmethodController", () => {
- +
- + @@ -61,39 +61,6 @@ describe("PaymentmethodController", () => { expect(paymentMethod3Container.style.display).toBe("block"); }); - it("handle well the add/remove on 'required' attribute on each input", () => { - const paymentMethod1 = document.getElementById("paymentmethod_1"); - const paymentMethod2 = document.getElementById("paymentmethod_2"); - const paymentMethod3 = document.getElementById("paymentmethod_3"); - - const input1 = document.getElementById("input1"); - const input2 = document.getElementById("input2"); - const input3 = document.getElementById("input3"); - - paymentMethod1.click(); - expect(input1.required).toBe(true); - expect(input2.dataset.required).toBe("true"); - expect(input2.required).toBe(false); - expect(input3.required).toBe(false); - - paymentMethod2.click(); - expect(input2.required).toBe(true); - expect(input1.dataset.required).toBe("true"); - expect(input1.required).toBe(false); - expect(input3.required).toBe(false); - - paymentMethod3.click(); - expect(input1.required).toBe(false); - expect(input2.required).toBe(false); - expect(input3.required).toBe(false); - - paymentMethod1.click(); - expect(input1.required).toBe(true); - expect(input2.dataset.required).toBe("true"); - expect(input2.required).toBe(false); - expect(input3.required).toBe(false); - }); - it("handle well the add/remove 'disabled='disabled'' attribute on each input/select", () => { const paymentMethod1 = document.getElementById("paymentmethod_1"); const paymentMethod2 = document.getElementById("paymentmethod_2");