diff --git a/lib/bitstyles_phoenix/component/form.ex b/lib/bitstyles_phoenix/component/form.ex
index 5692003..2e3b8ab 100644
--- a/lib/bitstyles_phoenix/component/form.ex
+++ b/lib/bitstyles_phoenix/component/form.ex
@@ -353,6 +353,25 @@ defmodule BitstylesPhoenix.Component.Form do
"""
)
+ story(
+ "Checkbox with custom value",
+ """
+ iex> assigns=%{form: form()}
+ ...> render ~H\"""
+ ...> <.ui_input form={@form} field={:accept} type={:checkbox} label_opts={[class: "extra"]} checked_value="123" unchecked_value="" />
+ ...> \"""
+ """,
+ """
+ \"""
+
+ \"""
+ """
+ )
+
def ui_input(assigns) do
extra = assigns_to_attributes(assigns, @wrapper_assigns_keys ++ [:type])
@@ -961,20 +980,33 @@ defmodule BitstylesPhoenix.Component.Form do
def ui_raw_input(%{type: "checkbox"} = assigns) do
assigns =
- assign_new(assigns, :checked, fn ->
+ assigns
+ |> assign_new(:checked, fn ->
PhxForm.normalize_value("checkbox", assigns[:value])
end)
+ |> assign_new(:checked_value, fn -> "true" end)
+ |> assign_new(:unchecked_value, fn -> "false" end)
+
+ extra =
+ assigns_to_attributes(assigns, [
+ :id,
+ :name,
+ :checked,
+ :value,
+ :type,
+ :checked_value,
+ :unchecked_value
+ ])
- extra = assigns_to_attributes(assigns, [:id, :name, :checked, :value, :type])
assigns = assign(assigns, extra: extra)
~H"""
-
+