Keenmate.WebMultiselect.OptionHelpers (Keenmate.WebMultiselect v1.0.0-rc.1)

Copy Markdown View Source

Converts the Components.web_multiselect/1 assigns into a map of HTML attributes shaped the way <web-multiselect> expects them.

Summary

Functions

Encodes an options list into the JSON shape <web-multiselect> reads from its options attribute.

Builds the map of HTML attributes for the underlying <web-multiselect> element.

Functions

encode_options(list)

@spec encode_options(term()) :: String.t()

Encodes an options list into the JSON shape <web-multiselect> reads from its options attribute.

Accepts:

  • [{value, label}, ...] tuple lists,
  • [%{value: ..., label: ...}, ...] maps (extra keys preserved),
  • any list — passed through to Jason.encode!/1 as-is.

to_html_attributes(assigns)

@spec to_html_attributes(map()) :: map()

Builds the map of HTML attributes for the underlying <web-multiselect> element.

  • Drops keys whose value is nil.
  • Renames snake_case keys to kebab-case.
  • Renders booleans as explicit "true" / "false" strings (the upstream component expects multiple="false", not a missing attribute).
  • Encodes options and initial_values as JSON.