-
Notifications
You must be signed in to change notification settings - Fork 29
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: Multiple inputs named with [] #93
Conversation
@@ -124,6 +132,8 @@ defmodule PhoenixTest.Form do | |||
defp to_form_field(name_element, value_element) do | |||
name = Html.attribute(name_element, "name") | |||
value = Html.attribute(value_element, "value") | |||
list? = String.ends_with?(name, "[]") | |||
value = if list?, do: [value], else: value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@totaltrash already mentioned Plug.Conn.Query.decode/4.
Would be great to reuse that to ensure we decode (nested) form data in the same way Phoenix and LiveView do.
Would get rid of some code here, and be more expressive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #94
Fixes #77 Replaces #79, #90, #93 ## Goal Ensure same form handling semantics as Phoenix controllers and LiveView. ## Details Track form data as a flat list of `{name, value}` tuples instead of nested maps. This can be read straight from the DOM and needs no further conversions. Example: ```ex form_data = [ {"user[name]", "Ada"}, {"user[subscribe][]", "email"}, {"user[subscribe][]", "push"} ] ``` Defer transforming that flat list into a nested data structure: When submitting form or evaluating other LiveLive `phx-*` callbacks. Use [Plug.Conn.Query.decode/4](https://github.com/elixir-plug/plug/blob/v1.16.0/lib/plug/conn/query.ex#L9) to transform flat list into nested data structure. Reason: Phoenix Controllers and LiveView do the same (see #77 (comment)).
Fixes #77
Replaces #79