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



23
24
25
26
# File 'lib/tabular_form_builder.rb', line 23

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



42
43
44
45
46
47
48
49
50
# File 'lib/tabular_form_builder.rb', line 42

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", text, 
                                   :class => (@object && @object.errors[field] ? "error" : nil), 
                                   :for => (@object_name.to_s + "_" + field.to_s))
end

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



37
38
39
# File 'lib/tabular_form_builder.rb', line 37

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