Class: TabularFormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Includes:
Redmine::I18n
Defined in:
lib/tabular_form_builder.rb

Instance Method Summary collapse

Methods included from Redmine::I18n

#current_language, #day_name, #find_language, #format_date, #format_time, included, #l, #l_hours, #l_or_humanize, #ll, #month_name, #set_language_if_valid, #valid_languages

Constructor Details

#initialize(object_name, object, template, options, proc) ⇒ TabularFormBuilder

Returns a new instance of TabularFormBuilder



20
21
22
23
# File 'lib/tabular_form_builder.rb', line 20

def initialize(object_name, object, template, options, proc)
  set_language_if_valid options.delete(:lang)
  super
end

Instance Method Details

#label_for_field(field, options = {}) ⇒ Object

Returns a label tag for the given field



39
40
41
42
43
44
45
46
# File 'lib/tabular_form_builder.rb', line 39

def label_for_field(field, options = {})
    return '' if options.delete(:no_label)
    text = options[:label].is_a?(Symbol) ? l(options[:label]) : options[:label]
    text ||= l(("field_" + field.to_s.gsub(/\_id$/, "")).to_sym)
    text += @template.("span", " *", :class => "required") if options.delete(:required)
    @template.label(@object_name, field.to_s, text,
                                   :class => (@object && @object.errors[field] ? "error" : nil))
end

#select(field, choices, options = {}, html_options = {}) ⇒ Object



34
35
36
# File 'lib/tabular_form_builder.rb', line 34

def select(field, choices, options = {}, html_options = {})
  label_for_field(field, options) + super
end