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

Fixing select[multiple] html specification problem. #1552

Merged
merged 1 commit into from Jun 11, 2011
Merged

Fixing select[multiple] html specification problem. #1552

merged 1 commit into from Jun 11, 2011

Conversation

bogdan
Copy link
Contributor

@bogdan bogdan commented Jun 8, 2011

There is very good work around for deselected check box in FormHelper#check_box.

I think it's good idea to use same work around for select[multiple] that have the same problem:

Server do not receive any value when all options got deselected.

So we will generate hidden input with the same name and blank value before each multiple select.

Generating hidden input with same name before each multiple select
drogus added a commit that referenced this pull request Jun 11, 2011
Fixing select[multiple] html specification problem.
@drogus drogus merged commit f5e1548 into rails:master Jun 11, 2011
drogus added a commit that referenced this pull request Jun 11, 2011
jake3030 pushed a commit to jake3030/rails that referenced this pull request Jun 28, 2011
[rails#1552 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
def test_select_with_multiple_to_add_hidden_input
output_buffer = select(:post, :category, "", {}, :multiple => true)
assert_dom_equal(
"<input type=\"hidden\" name=\"post[category][]\" value=\"\"/><select multiple=\"multiple\" id=\"post_category\" name=\"post[category][]\"></select>",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bogdan it looks like the value from the hidden field will not be overwritten since the field name contains [] in the end. So for the case when nothing selected it will pass:

{post: {category: [""]}}

and for the case when something was selected:

{post: {category: ["", "Category 1", "Category 2"]}}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it works as you said for nothing. As this patch got accepted: this behavior is expected, but it is not perfect as we expect to pass {post: {category: []}}, but I don't know how to do that.

The case when something is selected: Are you sure?

I would recommend the following workaround anyway: http://stackoverflow.com/questions/8929230/why-is-the-first-element-always-blank-in-my-rails-multi-select-using-an-embedde/8939205#8939205

@taelor
Copy link

taelor commented Mar 5, 2013

The case when something is selected: Are you sure?

I am sure, I am also seeing this, and its actually kind of annoying. I'd rather not have to clean up params in my controller because of Rails magic silently adding things. I am not even using this for updating a model, but I do use it when trying to query against a list of users belonging to different organizations. This is what comes over when you have one or more selected:

"organization_ids"=>["", "66284513", "676685643"]

While I would prefer not to have the hidden field generated at all, is there anyway we could throw an option to not have the hidden field generate?

@jtomasrl
Copy link

same problem here

@angelsystem
Copy link

There, same problem too

senny added a commit that referenced this pull request Jul 17, 2014
[Jonas Baumann & Yves Senn]

The submitted params from a select with `multiple: true` look as follows:

```
{post: {category: [""]}}

{post: {category: ["", "Category 1", "Category 2"]}}
```

This is a follow up to #1552.
senny added a commit that referenced this pull request Jul 17, 2014
[Jonas Baumann & Yves Senn]

The submitted params from a select with `multiple: true` look as follows:

```
{post: {category: [""]}}

{post: {category: ["", "Category 1", "Category 2"]}}
```

This is a follow up to #1552.
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

Successfully merging this pull request may close these issues.

None yet

6 participants