MishkaGervaz.Form.Web.Events.RelationHandler behaviour (MishkaGervaz v0.0.1-alpha.2)

Copy Markdown View Source

Handles relation field events for search, multi-select, and dropdown state.

Follows the same pattern as MishkaGervaz.Table.Web.Events.RelationFilterHandler.

Events Handled

  • search - Search options by term (debounced)
  • focus - Open dropdown and load initial options
  • close_dropdown - Close dropdown on click-away
  • select - Single select (for :search mode)
  • toggle - Toggle selection (for :search_multi mode)
  • clear - Clear all selections
  • load_more - Load next page of options

Customization

defmodule MyApp.Form.RelationHandler do
  use MishkaGervaz.Form.Web.Events.RelationHandler

  def handle("toggle", params, state, socket) do
    super("toggle", params, state, socket)
  end
end

Top-level helpers (get_field/2, get_search_term/2, validate_min_chars/2, resolve_selected_options/3, revalidate_form/3, update_relation_state/5, reload_dependent_fields/3, etc.) are public so user overrides can reuse them — they live outside the __using__ macro to avoid per-consumer compile cost.

See MishkaGervaz.Form.Web.Events, MishkaGervaz.Form.Web.DataLoader.RelationLoader, and the sibling sub-handlers.

Summary

Types

params()

@type params() :: map()

socket()

@type socket() :: Phoenix.LiveView.Socket.t()

state()

@type state() :: MishkaGervaz.Form.Web.State.t()

Callbacks

handle(action, params, state, socket)

@callback handle(
  action :: String.t(),
  params :: params(),
  state :: state(),
  socket :: socket()
) ::
  {:noreply, socket()}