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

Set default actions for forms #180

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
Set default actions for forms
When a form does not have an explicit action set it will do the action
to the current url.
  • Loading branch information
fatboypunk committed Nov 27, 2023
commit d9a81840921cfa84b220f9d9c89c348c6ad5a065
5 changes: 4 additions & 1 deletion lib/test_dispatch/form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ defmodule TestDispatch.Form do

defp resolve_nested(key), do: String.split(key, ["[", "]"], trim: true)

@spec send_to_action(map() | Keyword.t(), binary(), Plug.Conn.t()) :: Plug.Conn.t()
def send_to_action(params, form, conn) do
endpoint = endpoint_module(conn)
method = get_method_of_form(form)
action = floki_attribute(form, "action")

action = floki_attribute(form, "action") || conn.request_path

dispatch(conn, endpoint, method, action, params)
end
Expand All @@ -131,6 +133,7 @@ defmodule TestDispatch.Form do
defp downcase(nil), do: nil
defp downcase(string), do: String.downcase(string)

@spec find_form(Plug.Conn.t(), binary() | Keyword.t() | tuple()) :: {binary(), atom()}
def find_form(%Plug.Conn{status: status} = conn, entity_or_test_selector)
when status in 200..299 or status == 401 do
conn
Expand Down