Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow showing false values for boolean select inputs #74

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading