Automatically bind toggleCheckbox action

This commit is contained in:
David Cook
2025-02-20 11:23:57 +11:00
parent b92c046119
commit b370b207b5
5 changed files with 8 additions and 8 deletions

View File

@@ -23,7 +23,7 @@
%tr{id: supplied_product.semanticId }
%td
%label
= form.check_box 'semanticIds[]', { checked: true, data: { "action" => "change->checked#toggleCheckbox", "checked-target" => "checkbox" } }, supplied_product.semanticId, ""
= form.check_box 'semanticIds[]', { checked: true, 'data-checked-target': "checkbox" }, supplied_product.semanticId, ""
= supplied_product.name
%td
- if existing_product.present?

View File

@@ -36,7 +36,7 @@
distributor_shipping_method.id,
@order_cycle.distributor_shipping_methods.include?(distributor_shipping_method),
id: "order_cycle_selected_distributor_shipping_method_ids_#{distributor_shipping_method.id}",
data: ({ "action" => "change->checked#toggleCheckbox", "checked-target" => "checkbox" } if distributor_shipping_method.shipping_method.frontend?)
data: ({ "checked-target" => "checkbox" } if distributor_shipping_method.shipping_method.frontend?)
= distributor_shipping_method.shipping_method.name
- distributor.shipping_methods.backend.each do |shipping_method|
%label.disabled
@@ -67,7 +67,7 @@
distributor_payment_method.id,
@order_cycle.distributor_payment_methods.include?(distributor_payment_method),
id: "order_cycle_selected_distributor_payment_method_ids_#{distributor_payment_method.id}",
data: ({ "action" => "change->checked#toggleCheckbox", "checked-target" => "checkbox" } if distributor_payment_method.payment_method.frontend?)
data: ({ "checked-target" => "checkbox" } if distributor_payment_method.payment_method.frontend?)
= distributor_payment_method.payment_method.name
- distributor.payment_methods.inactive_or_backend.each do |payment_method|
%label.disabled

View File

@@ -1,6 +1,6 @@
%tr{ id: dom_id(order), class: "state-#{order.state}" }
%td.align-left
%input{type: 'checkbox', value: order.id, name: 'bulk_ids[]', "data-checked-target": "checkbox", "data-action": "change->checked#toggleCheckbox" }
%input{type: 'checkbox', value: order.id, name: 'bulk_ids[]', "data-checked-target": "checkbox" }
%td.align-left
= order.distributor.name
%td.align-left

View File

@@ -8,6 +8,10 @@ export default class extends Controller {
this.toggleCheckbox();
this.allTarget.addEventListener("change", this.toggleAll.bind(this));
this.checkboxTargets.forEach((checkbox) => {
checkbox.addEventListener("change", this.toggleCheckbox.bind(this));
});
}
toggleAll() {

View File

@@ -21,12 +21,10 @@ describe("CheckedController", () => {
<input
id="checkboxA"
type="checkbox"
data-action="change->checked#toggleCheckbox"
data-checked-target="checkbox">
<input
id="checkboxB"
type="checkbox"
data-action="change->checked#toggleCheckbox"
data-checked-target="checkbox">
</div>
`;
@@ -90,13 +88,11 @@ describe("CheckedController", () => {
<input
id="checkboxA"
type="checkbox"
data-action="change->checked#toggleCheckbox"
data-checked-target="checkbox"
checked="checked">
<input
id="checkboxB"
type="checkbox"
data-action="change->checked#toggleCheckbox"
data-checked-target="checkbox"
checked="checked">
</div>