Keenmate.WebMultiselect (Keenmate.WebMultiselect v1.0.0-rc.2)

Copy Markdown View Source

Phoenix wrapper for the @keenmate/web-multiselect custom element.

See Keenmate.WebMultiselect.Components.web_multiselect/1 for the component, and the README for how to wire up the bundled JS, CSS, and the optional LiveView hook.

Summary

Functions

Absolute on-disk path to a file shipped in priv/static/.

Pushes an update to a mounted <web-multiselect> from the server.

The version of @keenmate/web-multiselect bundled with this release.

Functions

asset_path(filename)

@spec asset_path(String.t()) :: String.t()

Absolute on-disk path to a file shipped in priv/static/.

Useful for setup tasks that copy assets into a host application's assets/ folder.

Keenmate.WebMultiselect.asset_path("multiselect.js")
#=> "/.../keen_web_multiselect/priv/static/multiselect.js"

push_update(socket, id, opts \\ [])

Pushes an update to a mounted <web-multiselect> from the server.

This is the sanctioned way to change a multiselect's option list or selection from the LiveView process. The component renders phx-update="ignore", so LV's DOM patcher won't propagate attribute changes to it — this helper sends the "web_multiselect:update" event that KeenWebMultiselectHook listens for and applies via el.options = ... / el.setSelected(...).

Requires the target element to have hook={true} (or hook="KeenWebMultiselectHook") and a matching id.

Options

  • :options — replace the option list (any shape the component accepts).
  • :value — replace the selection. A list sets multiple; a scalar wraps to a single selection; nil or [] clears it.

Only the keys you pass are sent, so push_update(socket, "id", value: []) clears the selection without touching the options, and push_update(socket, "id", options: opts) swaps options while leaving the selection to the component.

Examples

# Cascade: parent changed, load and push the child's options, reset selection
def handle_event("web_multiselect:change", %{"id" => "country", "values" => [c]}, socket) do
  {:noreply, Keenmate.WebMultiselect.push_update(socket, "region", options: regions(c), value: [])}
end

# Server-authoritative correction
Keenmate.WebMultiselect.push_update(socket, "tags", value: Enum.take(values, 3))

upstream_version()

@spec upstream_version() :: String.t()

The version of @keenmate/web-multiselect bundled with this release.