Skip to content

Feature request: support multiple count targets in SelectionFormController #130

@sobakasu

Description

@sobakasu

Motivation:
to be able to use the 'count' of selected items in button text or other customised selection text.

specifically this code:

  countValueChanged(count) {
    this.element.toggleAttribute("hidden", count === 0);
    this.countTarget.textContent = count;
    this.singularTarget.toggleAttribute("hidden", count !== 1);
    this.pluralTarget.toggleAttribute("hidden", count === 1);
  }

was thinking something like this:

  countValueChanged(count) {
    this.element.toggleAttribute("hidden", count === 0);
    this.countTargets.forEach((el) => el.textContent = count; });
    this.singularTargets.forEach((el) => el.toggleAttribute("hidden", count !== 1); });
    this.pluralTargets.forEach((el) => el.toggleAttribute("hidden", count === 1); });
  }

The other problem is how to use this feature nicely in the view.
(not nice example)

  <%= table_selection_with(collection:) do %>
    <%= tag.button formaction: "#", formmethod: :get do %>
      <span data-<%= Katalyst::Tables::Selectable::FormComponent.new(collection:).send(:form_target, "count") %>>0</span>
      Hello
    <% end %>
    <%= tag.button "Activate", formaction: "#", formmethod: :put %>
  <% end %>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions