I want to disable an HTML DropDown in Rails, and I found this solution:
how to disable the entire dropdown control in html
So, I have this:
f.select( ...., :disabled => true)
But, the problem is, when the DropDown is disabled, it does not show in the params collection.
EDIT:
This is my situation:
I have a form with a text_field and a select field. There are two cases:
- The user creates a new item directly. If so, she will choose a category from the select field.
- The user creates a new item, after redirecting from a category page. In this case, the select field is set to the value of the category, and should be disabled.
Does anyone have any idea how to fix this?
As mentioned in my comment in the original question, disabled form element values won’t be present in the params on a form submission. To get around this, try using a hidden field to hold and submit the value you want.
Assuming some variables and whatnot are setup to help decide whether the select field should be disabled:
Obviously this can be changed to suit your needs, but the basic idea is there. If you’ve already chosen a category and want the select field to be disabled, make a hidden field. If you haven’t chosen a category, omit the hidden field and allow users to make use of the select field.
As shown in the link I posted, this is probably the simplest way to get around this limitation, without resorting to using Javascript to play with parameters after form submission.