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



35
36
37
# File 'lib/redmine/views/labelled_form_builder.rb', line 35

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



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

def hours_field(field, options={})
  # display the value before type cast when the entered value is not valid
  if @object.errors[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



57
58
59
60
61
62
63
64
65
66
# File 'lib/redmine/views/labelled_form_builder.rb', line 57

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 ||= @object.class.human_attribute_name(field)
  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



39
40
41
# File 'lib/redmine/views/labelled_form_builder.rb', line 39

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



43
44
45
# File 'lib/redmine/views/labelled_form_builder.rb', line 43

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