Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added a :name option to input_fieldset which is passed along to gener…

…ate a legend tag inside the fieldset
  • Loading branch information...
commit a0e26578ebb2214ca6e9b790375140dc20545001 1 parent 76f60f5
Justin French authored
Showing with 14 additions and 4 deletions.
  1. +2 −2 README.textile
  2. +12 −2 lib/justin_french/formtastic.rb
4 README.textile
View
@@ -11,7 +11,7 @@ Hacked together forms were easy, but awesome forms with decent semantics, rich m
<%= form.error_messages %>
- <% form.input_field_set "Basic" do %>
+ <% form.input_field_set :name => "Basic" do %>
<%= form.input :title %>
<%= form.input :body, :rows => 20 %>
<%= form.input :section_id, :include_blank => true %>
@@ -20,7 +20,7 @@ Hacked together forms were easy, but awesome forms with decent semantics, rich m
<%= form.input :allow_comments, :label => "Allow commenting on this article" %>
<% end %>
- <% form.input_field_set "Extra" do %>
+ <% form.input_field_set :name => "Advanced" do %>
<%= form.input :keywords, :required => false, :hint => "Example: ruby, rails, forms" %>
<%= form.input :extract, :required => false, :rows => 5 %>
<%= form.input :description, :required => false, :rows => 5 %>
14 lib/justin_french/formtastic.rb
View
@@ -123,14 +123,21 @@ def input(method, options = {})
# <% input_field_set :id => "main-inputs" do %>
# ...
# <% end %>
+ #
+ # One special option exists (:name), which is passed along to a legend tag within the
+ # fieldset (otherwise a legend is not generated):
+ #
+ # <% input_field_set :name => "Advanced Options" do %>...<% end %>
def input_field_set(field_set_html_options = {}, &block)
- field_set_html_options[:class] ||= "inputs"
+ options[:class] ||= "inputs"
field_set_and_list_wrapping(field_set_html_options, &block)
end
# Creates a fieldset and ol tag wrapping for form buttons / actions as list items.
# See input_field_set documentation for a full example. The fieldset's default class attriute
# is set to "buttons".
+ #
+ # See input_field_set for html attriutes and special options.
def button_field_set(field_set_html_options = {}, &block)
field_set_html_options[:class] ||= "buttons"
field_set_and_list_wrapping(field_set_html_options, &block)
@@ -370,9 +377,12 @@ def required_or_optional_string(required) #:nodoc:
end
def field_set_and_list_wrapping(field_set_html_options, &block) #:nodoc:
+ legend_text = field_set_html_options.delete(:name)
+ legend = legend_text.blank? ? "" : @template.content_tag(:legend, @template.content_tag(:span, legend_text))
+
@template.concat(
@template.content_tag(:fieldset,
- @template.content_tag(:ol, @template.capture(&block)),
+ legend + @template.content_tag(:ol, @template.capture(&block)),
field_set_html_options
),
block.binding
Please sign in to comment.
Something went wrong with that request. Please try again.