defmodule Backpex.Fields.Boolean do @config_schema [ debounce: [ doc: "Timeout value (in milliseconds), \"blur\" or function that receives the assigns.", type: {:or, [:pos_integer, :string, {:fun, 1}]} ], throttle: [ doc: "Timeout value (in milliseconds) or function that receives the assigns.", type: {:or, [:pos_integer, {:fun, 1}]} ] ] @moduledoc """ A field for handling a boolean value. ## Field-specific options See `Backpex.Field` for general field options. #{NimbleOptions.docs(@config_schema)} """ use Backpex.Field, config_schema: @config_schema @impl Backpex.Field def render_value(assigns) do ~H"""
""" end @impl Backpex.Field def render_form(assigns) do ~H"""
<:label align={Backpex.Field.align_label(@field_options, assigns, :top)}>
""" end @impl Backpex.Field def render_index_form(assigns) do form = to_form(%{"value" => assigns.value}, as: :index_form) assigns = assigns |> assign_new(:form, fn -> form end) |> assign_new(:valid, fn -> true end) ~H"""
<.form for={@form} class="relative" phx-change="update-field" phx-submit="update-field" phx-target={@myself}>
""" end @impl Phoenix.LiveComponent def handle_event("update-field", %{"index_form" => %{"value" => value}}, socket) do Backpex.Field.handle_index_editable(socket, value, Map.put(%{}, socket.assigns.name, value)) end end