Skip to content
This repository
Browse code

add 'include_hidden' option to select tag, closes #5402

  • Loading branch information...
commit 54a75e1a0f1c2369a9a4b2872c2213d32a8bc117 1 parent 21b69b2
Vasiliy Ermolovich authored March 13, 2012
2  actionpack/CHANGELOG.md

Rails 4.0.0 (unreleased)

  • Add include_hidden option to select tag. With :include_hidden => true select with multiple attribute doesn't generate hidden input with blank value. Vasiliy Ermolovich

  • Removed default size option from the text_field, search_field, telephone_field, url_field, email_field helpers. Philip Arndt

  • Removed default cols and rows options from the text_area helper. Philip Arndt

  • Adds support for layouts when rendering a partial with a given collection. serabe

  • Allows the route helper root to take a string argument. For example, root 'pages#main'. bcardarella

  • Forms of persisted records use always PATCH (via the _method hack). fxn

  • For resources, both PATCH and PUT are routed to the update action. fxn

  • Don't ignore force_ssl in development. This is a change of behavior - use a :if condition to recreate the old behavior.

    class AccountsController < ApplicationController
      force_ssl :if => :ssl_configured?
    
      def ssl_configured?
        !Rails.env.development?
      end
    end
    

    Pat Allan

  • Adds support for the PATCH verb:

    • Request objects respond to patch?.
    • Routes have a new patch method, and understand :patch in the existing places where a verb is configured, like :via.
    • New method patch available in functional tests.
    • If :patch is the default verb for updates, edits are tunneled as PATCH rather than as PUT, and routing acts accordingly.
    • New method patch_via_redirect available in integration tests.

    dlee

  • Integration tests support the OPTIONS method. Jeremy Kemper

  • expires_in accepts a must_revalidate flag. If true, "must-revalidate" is added to the Cache-Control header. fxn

  • Add date_field and date_field_tag helpers which render an input[type="date"] tag Olek Janiszewski

  • Adds image_url, javascript_url, stylesheet_url, audio_url, video_url, and font_url to assets tag helper. These URL helpers will return the full path to your assets. This is useful when you are going to reference this asset from external host. Prem Sichanugrist

  • Default responder will now always use your overridden block in respond_with to render your response. Prem Sichanugrist

  • Allow value_method and text_method arguments from collection_select and options_from_collection_for_select to receive an object that responds to :call, such as a proc, to evaluate the option in the current element context. This works the same way with collection_radio_buttons and collection_check_boxes.

    Carlos Antonio da Silva + Rafael Mendonça França

  • Add collection_check_boxes form helper, similar to collection_select: Example:

    collection_check_boxes :post, :author_ids, Author.all, :id, :name # Outputs something like: D. Heinemeier Hansson D. Thomas

    The label/check_box pairs can be customized with a block.

    Carlos Antonio da Silva + Rafael Mendonça França

  • Add collection_radio_buttons form helper, similar to collection_select: Example:

    collection_radio_buttons :post, :author_id, Author.all, :id, :name # Outputs something like: D. Heinemeier Hansson D. Thomas

    The label/radio_button pairs can be customized with a block.

    Carlos Antonio da Silva + Rafael Mendonça França

  • check_box with :form html5 attribute will now replicate the :form attribute to the hidden field as well. Carlos Antonio da Silva

  • label form helper accepts :for => nil to not generate the attribute. Carlos Antonio da Silva

  • Add :format option to number_to_percentage Rodrigo Flores

  • Add config.action_view.logger to configure logger for ActionView. Rafael Mendonça França

  • Deprecated ActionController::Integration in favour of ActionDispatch::Integration

  • Deprecated ActionController::IntegrationTest in favour of ActionDispatch::IntegrationTest

  • Deprecated ActionController::PerformanceTest in favour of ActionDispatch::PerformanceTest

  • Deprecated ActionController::AbstractRequest in favour of ActionDispatch::Request

  • Deprecated ActionController::Request in favour of ActionDispatch::Request

  • Deprecated ActionController::AbstractResponse in favour of ActionDispatch::Response

  • Deprecated ActionController::Response in favour of ActionDispatch::Response

  • Deprecated ActionController::Routing in favour of ActionDispatch::Routing

  • check_box helper with :disabled => true will generate a disabled hidden field to conform with the HTML convention where disabled fields are not submitted with the form. This is a behavior change, previously the hidden tag had a value of the disabled checkbox. Tadas Tamosauskas

  • favicon_link_tag helper will now use the favicon in app/assets by default. Lucas Caton

  • ActionView::Helpers::TextHelper#highlight now defaults to the HTML5 mark element. Brian Cardarella

Rails 3.2.3 (unreleased)

... ...
@@ -1,5 +1,7 @@
1 1
 ## Rails 4.0.0 (unreleased) ##
2 2
 
  3
+*   Add `include_hidden` option to select tag. With `:include_hidden => true` select with `multiple` attribute doesn't generate hidden input with blank value. *Vasiliy Ermolovich*
  4
+
3 5
 *   Removed default `size` option from the `text_field`, `search_field`, `telephone_field`, `url_field`, `email_field` helpers. *Philip Arndt*
4 6
 
5 7
 *   Removed default `cols` and `rows` options from the `text_area` helper. *Philip Arndt*
2  actionpack/lib/action_view/helpers/form_options_helper.rb
@@ -153,6 +153,8 @@ module FormOptionsHelper
153 153
       # form, and parameters extraction gets the last occurrence of any repeated
154 154
       # key in the query string, that works for ordinary forms.
155 155
       #
  156
+      # In case if you don't want the helper to generate this hidden field you can specify <tt>:include_blank => false</tt> option.
  157
+      #
156 158
       def select(object, method, choices, options = {}, html_options = {})
157 159
         Tags::Select.new(object, method, self, choices, options, html_options).render
158 160
       end
3  actionpack/lib/action_view/helpers/tags/base.rb
@@ -122,7 +122,8 @@ def select_content_tag(option_tags, options, html_options)
122 122
           html_options = html_options.stringify_keys
123 123
           add_default_name_and_id(html_options)
124 124
           select = content_tag("select", add_options(option_tags, options, value(object)), html_options)
125  
-          if html_options["multiple"]
  125
+
  126
+          if html_options["multiple"] && options.fetch(:include_hidden) { true }
126 127
             tag("input", :disabled => html_options["disabled"], :name => html_options["name"], :type => "hidden", :value => "") + select
127 128
           else
128 129
             select
8  actionpack/test/template/form_options_helper_test.rb
@@ -529,6 +529,14 @@ def test_select_with_multiple_to_add_hidden_input
529 529
     )
530 530
   end
531 531
 
  532
+  def test_select_with_multiple_and_without_hidden_input
  533
+    output_buffer =  select(:post, :category, "", {:include_hidden => false}, :multiple => true)
  534
+    assert_dom_equal(
  535
+      "<select multiple=\"multiple\" id=\"post_category\" name=\"post[category][]\"></select>",
  536
+      output_buffer
  537
+    )
  538
+  end
  539
+
532 540
   def test_select_with_multiple_and_disabled_to_add_disabled_hidden_input
533 541
     output_buffer =  select(:post, :category, "", {}, :multiple => true, :disabled => true)
534 542
     assert_dom_equal(

0 notes on commit 54a75e1

Sergey Kojin

may be :include_hidden => false ?

Vasiliy Ermolovich

Indeed. I'll fix it. Thanks.

Please sign in to comment.
Something went wrong with that request. Please try again.