Skip to content

Commit

Permalink
fix: In AshPhoenix.Form.errors parse path before errors get (#300)
Browse files Browse the repository at this point in the history
fix: Make ash_errors private and remove unused default values
  • Loading branch information
ken-kost authored Jan 23, 2025
1 parent 1fea165 commit b38622b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/ash_phoenix/form/form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2718,12 +2718,12 @@ defmodule AshPhoenix.Form do
path ->
form
|> gather_errors(opts[:format])
|> Map.get(path)
|> Map.get(parse_path!(form, path))
|> List.wrap()
end
end

def ash_errors(form, opts \\ []) do
defp ash_errors(form, opts) do
form = to_form!(form)
opts = validate_opts_with_extra_keys(opts, @errors_opts)

Expand Down
10 changes: 7 additions & 3 deletions test/form_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ defmodule AshPhoenix.FormTest do
assert nested_form.errors == [{:text, {"is required", []}}]
end

test "errors with a path are propagated down to the appropirate nested form" do
test "errors with a path are propagated down to the appropirate nested form for list or string path" do
author = %Author{
email: "me@example.com"
}
Expand All @@ -1036,11 +1036,15 @@ defmodule AshPhoenix.FormTest do
|> Form.validate(%{"embedded_argument" => %{"value" => "you@example.com"}})
|> form_for("action")

assert AshPhoenix.Form.errors(form, for_path: [:embedded_argument]) == [
assert Form.errors(form, for_path: [:embedded_argument]) == [
value: "must match email"
]

assert AshPhoenix.Form.errors(form) == []
assert Form.errors(form, for_path: "form[embedded_argument]") == [
value: "must match email"
]

assert Form.errors(form) == []

# Check that errors will appear on a nested form using the Phoenix Core Components inputs_for
# https://github.com/phoenixframework/phoenix_live_view/blob/main/lib/phoenix_component.ex#L2410
Expand Down

0 comments on commit b38622b

Please sign in to comment.