Skip to content

Commit

Permalink
fix: allow showing false values for boolean selects (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
skanderm authored Nov 13, 2023
1 parent 07f1d6d commit fcf81d5
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions lib/ash_admin/components/resource/form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,8 @@ defmodule AshAdmin.Components.Resource.Form do
<%= Phoenix.HTML.Form.select(
@form,
@attribute.name,
[Nil: nil, True: "true", False: "false"],
[True: "true", False: "false"]
|> Keyword.merge(if @attribute.allow_nil?, do: [Nil: nil], else: []),
selected: value(@value, @form, @attribute),
name: @name || @form.name <> "[#{@attribute.name}]"
) %>
Expand Down Expand Up @@ -1021,15 +1022,13 @@ defmodule AshAdmin.Components.Resource.Form do

defp value({:value, value}, _, _), do: value

defp value(value, form, attribute) do
if value do
value
else
value = Phoenix.HTML.FormData.input_value(form.source, form, attribute.name)
defp value(value, _form, _attribute) when not is_nil(value), do: value

if value do
value
else
defp value(_value, form, attribute) do
value = Phoenix.HTML.FormData.input_value(form.source, form, attribute.name)

case value do
nil ->
case attribute.default do
nil ->
nil
Expand All @@ -1040,7 +1039,9 @@ defmodule AshAdmin.Components.Resource.Form do
default ->
default
end
end

value ->
value
end
end

Expand Down

0 comments on commit fcf81d5

Please sign in to comment.