Class: ActionView::Helpers::FormBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/required_field_style.rb

Instance Method Summary collapse

Instance Method Details

#label(method, content_or_options = nil, options = nil, &block) ⇒ Object

add a ‘*’ after the field label if the field is required and no configuration



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/required_field_style.rb', line 11

def label(method, content_or_options = nil, options = nil, &block)
  if content_or_options && content_or_options.class == Hash
    options = content_or_options
  else
    content = content_or_options
  end

  if ValidationChecker.mandatory_field?(object.class, method)
    if RequiredFieldStyle.configuration.css_class_name.blank?
      content ||= method.to_s.humanize
      content = content + '<sup style="color:red">&nbsp;*</sup>'.html_safe
    else
      options = {:class => RequiredFieldStyle.configuration.css_class_name}
    end
  end

  self.orig_label(method, content, options || {}, &block)
end

#orig_labelObject



8
# File 'lib/required_field_style.rb', line 8

alias :orig_label :label