Class: RulesEngineView::FormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Includes:
FormStyles
Defined in:
lib/rules_engine_view/form_builder.rb

Instance Method Summary collapse

Methods included from FormStyles

#re_build_form_data, #re_build_form_field, #re_build_form_label, #re_data_span, #re_error_on_tag, #re_field_span, #re_label_span, #re_options_exclude

Instance Method Details

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



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rules_engine_view/form_builder.rb', line 29

def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
  error = @object && @object.respond_to?(:errors) ? @object.errors[method.to_sym] : nil

  options.reverse_merge!(:error => error) unless error.blank?
  options.reverse_merge!(:span => @options[:span]) unless @options.nil? || @options[:span].blank?
  
  field_label = options[:label] || method.to_s.titleize        
  form_label = re_build_form_label(" ".html_safe, options.except(:required).merge(:span => re_label_span(options)))
  form_data_label = re_build_form_label(label(method, field_label, re_options_exclude(options)), re_options_exclude(options).merge(:required => options[:required]))        
  form_data = re_build_form_data(orig_check_box(method, re_options_exclude(options), checked_value, unchecked_value),  options.merge(:text => form_data_label, :class=>'re-form-field-checkbox', :span => re_data_span(options))) 
  re_build_form_field(form_label + form_data, options.merge(:span => re_field_span(options)))
end

#orig_check_boxObject



27
# File 'lib/rules_engine_view/form_builder.rb', line 27

alias_method :orig_check_box, :check_box

#re_error_on(message) ⇒ Object



42
43
44
45
46
# File 'lib/rules_engine_view/form_builder.rb', line 42

def re_error_on(message)
  return '' unless @object && @object.respond_to?(:errors)
  return '' if @object.errors.empty?
  re_error_on_tag(message)
end