Add select/deselect all checkbox

There's A Controller For That.
(But I think it makes the HTML ugly..)
This commit is contained in:
David Cook
2025-02-20 10:56:53 +11:00
parent 96b8a4c068
commit c2e54104d0
3 changed files with 15 additions and 3 deletions

View File

@@ -12,13 +12,18 @@
= form.hidden_field :enterprise_id, value: @enterprise.id
= form.hidden_field :catalog_json, value: @catalog_json
%table
%table{"data-controller": "checked" }
%thead
%tr
%th
%input{ type: 'checkbox', title: t('.select_all'), 'aria-label': t('.select_all'), data: { "checked-target": "all", action: "change->checked#toggleAll" } }
%th
%tbody
- @items.each do |supplied_product, existing_product|
%tr{id: supplied_product.semanticId }
%td
%label
= form.check_box 'semanticIds[]', { checked: true }, supplied_product.semanticId, ""
= form.check_box 'semanticIds[]', { checked: true, data: { "action" => "change->checked#toggleCheckbox", "checked-target" => "checkbox" } }, supplied_product.semanticId, ""
= supplied_product.name
%td
- if existing_product.present?

View File

@@ -851,6 +851,7 @@ en:
title: "DFC product catalog"
catalog_url: "%{count} products to be imported from: %{catalog_url}"
enterprise: "Import to enterprise: %{enterprise_name}"
select_all: "Select/deselect all"
update: Update
new: New
import: Import

View File

@@ -65,7 +65,13 @@ RSpec.describe "DFC Product Import" do
expect(page).to have_content "Beans - Case, 12 x 400g (can) New"
expect(page).to have_content "Chia Seed, Organic - Retail pack, 300g"
uncheck "Chia Seed, Organic - Case, 8 x 300g" # don't import this one
# I can select all
uncheck "Chia Seed, Organic - Case, 8 x 300g"
check "Select/deselect all"
expect(page).to have_checked_field "Chia Seed, Organic - Case, 8 x 300g"
# And deselect one
uncheck "Chia Seed, Organic - Case, 8 x 300g"
expect {
click_button "Import"