mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Remove unused code for changing required attributes
This commit is contained in:
@@ -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;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,13 +14,13 @@ describe("PaymentmethodController", () => {
|
||||
<input id="paymentmethod_3" data-action="click->paymentmethod#selectPaymentMethod" data-paymentmethod-id="paymentmethod3" data-paymentmethod-target="input"/>
|
||||
|
||||
<div class="paymentmethod-container" id="paymentmethod1">
|
||||
<input type="number" required id="input1" />
|
||||
<input type="number" id="input1" />
|
||||
<select id="select1" >
|
||||
<option value="1">1</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="paymentmethod-container" id="paymentmethod2">
|
||||
<input type="number" required="true" id="input2" />
|
||||
<input type="number" id="input2" />
|
||||
<select id="select2" >
|
||||
<option value="1">1</option>
|
||||
</select>
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user