Class: Redmine::Views::LabelledFormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Includes:
I18n
Defined in:
lib/redmine/views/labelled_form_builder.rb

Instance Method Summary collapse

Methods included from I18n

#current_language, #day_letter, #day_name, #find_language, #format_date, #format_hours, #format_time, included, #l, #l_hours, #l_hours_short, #l_or_humanize, #languages_options, #ll, #lu, #month_name, #set_language_if_valid, #valid_languages

Instance Method Details

#check_box(field, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object



33
34
35
# File 'lib/redmine/views/labelled_form_builder.rb', line 33

def check_box(field, options={}, checked_value="1", unchecked_value="0")
  label_for_field(field, options) + super(field, options.except(:label), checked_value, unchecked_value).html_safe
end

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

A field for entering hours value



46
47
48
49
50
51
52
# File 'lib/redmine/views/labelled_form_builder.rb', line 46

def hours_field(field, options={})
  # display the value before type cast when the entered value is not valid
  if @object.errors.get(field).blank?
    options = options.merge(:value => format_hours(@object.send field))
  end
  text_field field, options
end

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

Returns a label tag for the given field



55
56
57
58
59
60
61
62
63
# File 'lib/redmine/views/labelled_form_builder.rb', line 55

def label_for_field(field, options = {})
  return ''.html_safe 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.html_safe,
                                 :class => (@object && @object.errors[field].present? ? "error" : nil),
                                 :for => (@object_name.to_s + "_" + field.to_s))
end

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



37
38
39
# File 'lib/redmine/views/labelled_form_builder.rb', line 37

def select(field, choices, options = {}, html_options = {})
  label_for_field(field, options) + super(field, choices, options, html_options.except(:label)).html_safe
end

#time_zone_select(field, priority_zones = nil, options = {}, html_options = {}) ⇒ Object



41
42
43
# File 'lib/redmine/views/labelled_form_builder.rb', line 41

def time_zone_select(field, priority_zones = nil, options = {}, html_options = {})
  label_for_field(field, options) + super(field, priority_zones, options, html_options.except(:label)).html_safe
end