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

{ hash: true, empty: true } yields empty values for name[] (no index) #40

Open
nhunzaker opened this issue Jul 21, 2016 · 2 comments
Open

Comments

@nhunzaker
Copy link

I'm working on an app with the following inputs:

<input type="checkbox" name="types[]" value="activities" checked />
<input type="checkbox" name="types[]" value="games" />
<input type="checkbox" name="types[]" value="apps" />
<input type="checkbox" name="types[]" value="videos" checked />

I'm using { hash: true, empty: true } so that I can serialize down an empty types field. However the inputs that aren't checked are showing up in the serialized parameters like:

{
    "types": ["", "activities", "", "videos" ]
}

I would like:

{
    "types": ["activities", "videos" ]
}

and the following when no inputs are checked:

{
    "types": []
}

What do you think about stripping out unchecked boxes if the name field includes no index?

@defunctzombie
Copy link
Owner

Seems pretty reasonable if right now it just returns empty strings for those fields. What is the equivalent form-encoding string for the above input (i.e. when hash: false is used)

@nhunzaker
Copy link
Author

nhunzaker commented Aug 16, 2016

A quick test shows that it only includes the checked values, using:

<form action="/" method="POST">
  <input type="checkbox" name="types[]" value="activities" checked />
  <input type="checkbox" name="types[]" value="games" />
  <input type="checkbox" name="types[]" value="apps" />
  <input type="checkbox" name="types[]" value="videos" checked />
  <button type="submit">Go</button>
</form>

If I inspect the networking tab, only the checked inputs are included:

screen shot 2016-08-15 at 7 59 51 pm

I'll jam on this a bit and send out a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants