-
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
Support multiple checkboxes #77
Comments
Furthermore, I sometimes do similar with hidden inputs that are used to back an interactive component for searching and selecting for multiple values. |
I've been doing a bit of digging into how live view is handling this. Basically any param appended with Plug.Conn.Query.decode("roles[]=aaa&roles[]=bbb")
%{"roles" => ["aaa", "bbb"]}
My proposal would be to treat all submitted params in this way - any param ending in |
I think multiple selects should now be handled on |
Thanks @germsvel, I updated to main and unfortunately this is not handled - see PR for some failing tests |
If you extend your example like this: <label for="edit_user_form_roles">Roles</label>
<input id="edit_user_form_roles" name="roles" type="hidden" value="">
<div>
<input type="checkbox" name="roles[]" id="edit_user_form_roles_admin" value="admin">
<label for="edit_user_form_roles_admin">Administrator</label>
</div>
<div>
<input type="checkbox" name="roles[]" id="edit_user_form_roles_user" value="user">
<label for="edit_user_form_roles_user">User</label>
</div> then you can use session
|> fill_in("Roles", with: ["user", "admin"]) It's a bit of a hacky workaround but it works until there's proper support for this kind of form layout. N.B. the example above is what Petal Components does. They call it a checkbox group: @germsvel would it make sense to use the Petal Components lib as a testbed for PhoenixTest and its form features? |
@soundmonster to your question:
What do you have in mind? What do you mean by a testbed? (I'm assuming a helpful place to test each release of |
I'm hoping this is something that can be supported by PhoenixTest - this strategy was supported by the removed
fill_form
but no longer works with the new form helpers (check
etc.).As an alternative to multiple selects, sometimes I will use multiple checkboxes to emulate the behavior of a multiple select - here's a simple example:
Phoenix/LiveView handles this just fine, converting the params provided to
phx-change
andphx-submit
to%{"roles" => ["admin" , ...]}
.PhoenixTest, since the introduction of the new form handlers now results in:
The text was updated successfully, but these errors were encountered: