Incorrect handling of multi-parameter SELECTs when using both disabled and discard_foo #7431

Closed
nickgrim opened this Issue Aug 23, 2012 · 0 comments

Projects

None yet

2 participants

Short version:

When using a form helper on Rails 3.2.8 that generates multiple-SELECTs for multiparameter attributes (e.g. f.datetime_select) in combination with the :disabled option and not showing all of the SELECTs (e.g. by using :discard_minute => true), it fails to disable the hidden-fields that are created as placeholders for the discarded-fields.

To replicate:

  • Create a new Rails project (I'm using 3.2.8); run bundle install and all that jazz.
  • Scaffold a resource: rails generate scaffold Thing deetee:datetime disabled_deetee:datetime. Run db:migrate, etc.
  • Apply the following patch to app/views/things/_form.html.erb:
-    <%= f.datetime_select :disabled_deetee %>
+    <%= f.datetime_select :disabled_deetee, :discard_minute => true, :disabled => true %>
  • Go to /things/new, and submit the form.
  • Note the following in the logs:
Started POST "/things" for 127.0.0.1 at 2012-08-23 12:08:44 +0100
Processing by ThingsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"x5aiRvh4DilTiiNDm6y6qU7zqBjCUoxTy3hQNBzFVks=", "thing"=>{"deetee(1i)"=>"2012", "deetee(2i)"=>"8", "deetee(3i)"=>"23", "deetee(4i)"=>"11", "deetee(5i)"=>"08", "disabled_deetee(5i)"=>"8"}, "commit"=>"Create Thing"}
Completed 500 Internal Server Error in 2ms

ActiveRecord::MultiparameterAssignmentErrors (1 error(s) on assignment of multiparameter attributes):
  app/controllers/things_controller.rb:43:in `new'
  app/controllers/things_controller.rb:43:in `create'

...specifically, note that "disabled_deetee(5i)"=>"8" is posted.

The problem seems to be that the following (relevant) HTML is generated (with the <option>s removed for readability):

<div class="field">
  <label for="thing_disabled_deetee">Disabled deetee</label><br />
  <select disabled="disabled" id="thing_disabled_deetee_1i" name="thing[disabled_deetee(1i)]">...</select>
  <select disabled="disabled" id="thing_disabled_deetee_2i" name="thing[disabled_deetee(2i)]">...</select>
  <select disabled="disabled" id="thing_disabled_deetee_3i" name="thing[disabled_deetee(3i)]">...</select>
   &mdash; <select disabled="disabled" id="thing_disabled_deetee_4i" name="thing[disabled_deetee(4i)]">...</select>
  <input id="thing_disabled_deetee_5i" name="thing[disabled_deetee(5i)]" type="hidden" value="19" />
</div>

...and I believe that the <input type="hidden"> should also have a disabled="disabled" attribute.

@nashby nashby added a commit to nashby/rails that referenced this issue Aug 25, 2012
@nashby nashby correct handling of date selects when using both disabled and discard…
… options

we should take disabled option not only from `html_options` hash but from
`options` hash too like `build_select` method does it. So

datetime_select("post", "updated_at", { :discard_minute => true }, { :disabled => true })
datetime_select("post", "updated_at", :discard_minute => true , :disabled => true)

both these variants work now

closes #7431
feb7c71
@nashby nashby added a commit to nashby/rails that referenced this issue Aug 25, 2012
@nashby nashby correct handling of date selects when using both disabled and discard…
… options

we should take disabled option not only from `html_options` hash but from
`options` hash too like `build_select` method does it. So

datetime_select("post", "updated_at", { :discard_minute => true }, { :disabled => true })
datetime_select("post", "updated_at", :discard_minute => true , :disabled => true)

both these variants work now

closes #7431
130fe2b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment