From a2a64b058366415b7c90f98da063eb5cbea8f79d Mon Sep 17 00:00:00 2001 From: Jon Crawford Date: Fri, 5 Sep 2008 01:50:38 -0500 Subject: [PATCH] Added optgroups_with_options_for_select helper to form_options_helper for wrapping option tags in optgroups. --- .../lib/action_view/helpers/form_options_helper.rb | 46 +++++++++++++++++++- .../test/template/form_options_helper_test.rb | 29 ++++++++++++ 2 files changed, 74 insertions(+), 1 deletions(-) diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index 9aae945..2873d08 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -268,7 +268,51 @@ module ActionView options_for_select += '' end end - + + # Returns a string of tags, like options_from_collection_for_select, but + # wraps them with tags. + # + # Parameters: + # * +labels+ - An array of strings representing the text. + # * +options+ - An array of arrays each containing the options for a corresponding optgroup. + # * +selected_key+ - A value equal to the +value+ attribute for one of the tags, + # which will have the +selected+ attribute set. Corresponds to the return value of one of the calls + # to +option_key_method+. If +nil+, no selection is made. + # * +prompt+ - set to true or a prompt string. When the select element doesn’t have a value yet, this + # prepends an option with a generic prompt — "Please select" — or the given prompt string. + # + # + # Sample usage: + # labels = ['North America','Europe'] + # groups = [['United States','Canada'],['Denmark','Germany','France']] + # optgroups_with_options_for_select(labels,groups) + # + # Possible output: + # + # + # + # + # + # + # + # + # + # + # Note: Only the and tags are returned, so you still have to + # wrap the output in an appropriate