diff --git a/demo/lib/demo_web/live/home_live/index.html.heex b/demo/lib/demo_web/live/home_live/index.html.heex index 7a0f7762..a3334133 100644 --- a/demo/lib/demo_web/live/home_live/index.html.heex +++ b/demo/lib/demo_web/live/home_live/index.html.heex @@ -39,12 +39,7 @@ Get notified when we're launching. <.form :if={not @subscribed?} class="mt-4 flex gap-x-4" for={@form} phx-change="validate" phx-submit="subscribe"> - <%= Phoenix.HTML.Form.text_input( - @form, - :email, - class: "input input-bordered h-12 w-64" - ) %> - + diff --git a/lib/backpex/fields/belongs_to.ex b/lib/backpex/fields/belongs_to.ex index 773bc861..ad95f09a 100644 --- a/lib/backpex/fields/belongs_to.ex +++ b/lib/backpex/fields/belongs_to.ex @@ -10,7 +10,6 @@ defmodule Backpex.Fields.BelongsTo do * `:options_query` - Manipulates the list of available options in the select. Defaults to `fn (query, _field) -> query end` which returns all entries. * `:prompt` - The text to be displayed when no option is selected. - Allows the same values as [`Phoenix.Html.Form.select`](https://hexdocs.pm/phoenix_html/Phoenix.HTML.Form.html#select/4) for customization of the prompt. ## Example @@ -96,8 +95,7 @@ defmodule Backpex.Fields.BelongsTo do - - + """ diff --git a/lib/backpex/fields/currency.ex b/lib/backpex/fields/currency.ex index 4b42f11e..0eaa4bbf 100644 --- a/lib/backpex/fields/currency.ex +++ b/lib/backpex/fields/currency.ex @@ -63,8 +63,7 @@ defmodule Backpex.Fields.Currency do <.multi_select - form={@form} + field={@form[@name]} prompt={@prompt} not_found_text={@not_found_text} options={@options} selected={@selected} search_input={@search_input} - name={@name} field_options={@field_options} show_select_all={@show_select_all} show_more={@show_more} diff --git a/lib/backpex/fields/has_many_through.ex b/lib/backpex/fields/has_many_through.ex index 313f0b38..e58d4c81 100644 --- a/lib/backpex/fields/has_many_through.ex +++ b/lib/backpex/fields/has_many_through.ex @@ -533,13 +533,7 @@ defmodule Backpex.Fields.HasManyThrough do <:label> - + """ end diff --git a/lib/backpex/fields/inline_crud.ex b/lib/backpex/fields/inline_crud.ex index 5ce0b25f..57eb3ddd 100644 --- a/lib/backpex/fields/inline_crud.ex +++ b/lib/backpex/fields/inline_crud.ex @@ -131,8 +131,7 @@ defmodule Backpex.Fields.InlineCRUD do

Atom.to_string()} - form={f_nested} - field_name={child_field_name} + field={f_nested[child_field_name]} field_options={child_field_options} /> diff --git a/lib/backpex/fields/many_to_many.ex b/lib/backpex/fields/many_to_many.ex index 63b012ab..e682007f 100644 --- a/lib/backpex/fields/many_to_many.ex +++ b/lib/backpex/fields/many_to_many.ex @@ -216,13 +216,12 @@ defmodule Backpex.Fields.ManyToMany do <.multi_select - form={@form} + field={@form[@name]} prompt={@prompt} not_found_text={@not_found_text} options={@options} selected={@selected} search_input={@search_input} - name={@name} field_options={@field_options} show_select_all={@show_select_all} show_more={@show_more} diff --git a/lib/backpex/fields/multi_select.ex b/lib/backpex/fields/multi_select.ex index a1a75305..23ffc19f 100644 --- a/lib/backpex/fields/multi_select.ex +++ b/lib/backpex/fields/multi_select.ex @@ -128,13 +128,12 @@ defmodule Backpex.Fields.MultiSelect do <.multi_select - form={@form} + field={@form[@name]} prompt={@prompt} not_found_text={@not_found_text} options={@options} selected={@selected} search_input={@search_input} - name={@name} field_options={@field_options} show_select_all={@show_select_all} show_more={false} diff --git a/lib/backpex/fields/number.ex b/lib/backpex/fields/number.ex index 14b9cb17..dde53ae1 100644 --- a/lib/backpex/fields/number.ex +++ b/lib/backpex/fields/number.ex @@ -29,7 +29,7 @@ defmodule Backpex.Fields.Number do <:label align={Backpex.Field.align_label(@field_options, assigns)}> - + """ @@ -43,14 +43,7 @@ defmodule Backpex.Fields.Number do <:label align={Backpex.Field.align_label(@field_options, assigns)}> - + """ @@ -58,31 +51,24 @@ defmodule Backpex.Fields.Number do @impl Backpex.Field def render_index_form(assigns) do + form = to_form(%{"value" => assigns.value}, as: :index_form) + assigns = assigns - |> assign(:input_id, "index_input_#{assigns.item.id}_#{assigns.name}") + |> assign(:form, form) |> assign_new(:valid, fn -> true end) ~H"""
- <.form - :let={f} - for={%{}} - as={:index_form} - class="relative" - phx-change="update-field" - phx-submit="update-field" - phx-target={@myself} - > - <%= Phoenix.HTML.Form.text_input( - f, - :index_input, - class: ["input input-sm", if(@valid, do: "hover:input-bordered", else: "input-error")], - value: @value, - phx_debounce: "100", - readonly: @readonly, - id: @input_id - ) %> + <.form for={@form} class="relative" phx-change="update-field" phx-submit="update-field" phx-target={@myself}> +
""" diff --git a/lib/backpex/fields/select.ex b/lib/backpex/fields/select.ex index 81086172..a4d6c030 100644 --- a/lib/backpex/fields/select.ex +++ b/lib/backpex/fields/select.ex @@ -6,7 +6,6 @@ defmodule Backpex.Fields.Select do * `:options` - Required (keyword) list of options to be used for the select. * `:prompt` - The text to be displayed when no option is selected. - Allows the same values as [`Phoenix.Html.Form.select`](https://hexdocs.pm/phoenix_html/Phoenix.HTML.Form.html#select/4) for customization of the prompt. ## Example @@ -54,8 +53,7 @@ defmodule Backpex.Fields.Select do assigns.value}, as: :index_form) options = Map.get(assigns.field_options, :options) assigns = assigns - |> assign(:input_id, "index_input_#{assigns.item.id}_#{assigns.name}") - |> assign_new(:valid, fn -> true end) + |> assign(:form, form) |> assign(:options, options) + |> assign_new(:valid, fn -> true end) |> assign_prompt(assigns.field_options) ~H"""
- <.form - :let={f} - for={%{}} - as={:index_form} - class="relative" - phx-change="update-field" - phx-submit="update-field" - phx-target={@myself} - > - <%= Phoenix.HTML.Form.select( - f, - :index_input, - @options, - class: ["select select-sm", if(@valid, do: "hover:input-bordered", else: "select-error")], - selected: @value, - disabled: @readonly, - id: @input_id, - prompt: Map.get(@prompt, :prompt) - ) %> + <.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" => %{"index_input" => value}}, socket) do + def handle_event("update-field", %{"index_form" => %{"value" => value}}, socket) do Backpex.Field.handle_index_editable(socket, %{} |> Map.put(socket.assigns.name, value)) end diff --git a/lib/backpex/fields/text.ex b/lib/backpex/fields/text.ex index 1d05c980..56c62499 100644 --- a/lib/backpex/fields/text.ex +++ b/lib/backpex/fields/text.ex @@ -27,7 +27,7 @@ defmodule Backpex.Fields.Text do <:label align={Backpex.Field.align_label(@field_options, assigns, :center)}> - + """ @@ -41,14 +41,7 @@ defmodule Backpex.Fields.Text do <:label align={Backpex.Field.align_label(@field_options, assigns, :center)}> - + """ @@ -56,38 +49,31 @@ defmodule Backpex.Fields.Text do @impl Backpex.Field def render_index_form(assigns) do + form = to_form(%{"value" => assigns.value}, as: :index_form) + assigns = assigns - |> assign(:input_id, "index_input_#{assigns.item.id}_#{assigns.name}") + |> assign(:form, form) |> assign_new(:valid, fn -> true end) ~H"""
- <.form - :let={f} - for={%{}} - as={:index_form} - class="relative" - phx-change="update-field" - phx-submit="update-field" - phx-target={@myself} - > - <%= Phoenix.HTML.Form.text_input( - f, - :index_input, - class: ["input input-sm", if(@valid, do: "hover:input-bordered", else: "input-error")], - value: @value, - phx_debounce: "100", - readonly: @readonly, - id: @input_id - ) %> + <.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" => %{"index_input" => value}}, socket) do + def handle_event("update-field", %{"index_form" => %{"value" => value}}, socket) do Backpex.Field.handle_index_editable(socket, %{} |> Map.put(socket.assigns.name, value)) end end diff --git a/lib/backpex/fields/textarea.ex b/lib/backpex/fields/textarea.ex index f54a86b2..5be62021 100644 --- a/lib/backpex/fields/textarea.ex +++ b/lib/backpex/fields/textarea.ex @@ -27,7 +27,7 @@ defmodule Backpex.Fields.Textarea do <:label align={Backpex.Field.align_label(@field_options, assigns, :top)}> - + """ @@ -41,14 +41,7 @@ defmodule Backpex.Fields.Textarea do <:label align={Backpex.Field.align_label(@field_options, assigns, :top)}> - + """ diff --git a/lib/backpex/fields/url.ex b/lib/backpex/fields/url.ex index b3148b84..83bf0966 100644 --- a/lib/backpex/fields/url.ex +++ b/lib/backpex/fields/url.ex @@ -29,7 +29,7 @@ defmodule Backpex.Fields.URL do <:label align={Backpex.Field.align_label(@field_options, assigns)}> - + """ diff --git a/lib/backpex/filters/boolean.ex b/lib/backpex/filters/boolean.ex index 9d7de520..98e012aa 100644 --- a/lib/backpex/filters/boolean.ex +++ b/lib/backpex/filters/boolean.ex @@ -92,29 +92,27 @@ defmodule Backpex.Filters.Boolean do attr :options, :list, required: true def render_form(assigns) do - checked = if is_nil(assigns.value), do: [], else: assigns.value + value = if is_nil(assigns.value), do: [], else: assigns.value options = Enum.map(assigns.options, fn %{label: l, key: k} -> {l, k} end) assigns = assigns - |> assign(:checked, checked) + |> assign(:value, value) |> assign(:options, options) ~H"""
- <%= Phoenix.HTML.Form.hidden_input(@form, @field, name: Phoenix.HTML.Form.input_name(@form, @field), value: "") %> - <%= for {label, key} <- @options do %> + + <%= for {label, v} <- @options do %>