diff --git a/lib/doggo.ex b/lib/doggo.ex index 261bb4bf..2e34254d 100644 --- a/lib/doggo.ex +++ b/lib/doggo.ex @@ -929,7 +929,8 @@ defmodule Doggo do attr :type, :string, default: "text", values: ~w(checkbox color date datetime-local email file hidden month number - password range radio search select tel text textarea time url week) + password range radio search select switch tel text textarea time url + week) attr :field, Phoenix.HTML.FormField, doc: "A form field struct, for example: @form[:name]" @@ -1016,6 +1017,47 @@ defmodule Doggo do """ end + def input(%{type: "switch"} = assigns) do + assigns = + assign_new(assigns, :checked, fn -> + Form.normalize_value("checkbox", assigns[:value]) + end) + + ~H""" +
+ <.label required={@validations[:required] || false} class="switch"> + <%= @label %> + + + + + + + <.field_errors for={@id} errors={@errors} /> + <.field_description for={@id} description={@description} /> +
+ """ + end + def input(%{type: "select"} = assigns) do ~H"""