class Lev::FormBuilder

Public Instance Methods

check_box(method, options = {}, checked_value = "1", unchecked_value = "0") click to toggle source
Calls superclass method
# File lib/lev/form_builder.rb, line 16
def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
  options[:checked] = true if get_form_params_entry(method).to_i > 0
  mark_error_if_present(method, options)
  super(method, options, checked_value, unchecked_value)
end
fields_for(record_name, record_object = nil, fields_options = {}, &block) click to toggle source
# File lib/lev/form_builder.rb, line 28
def fields_for(record_name, record_object = nil, fields_options = {}, &block)
  raise "Didn't put fields_for into LevitateFormBuilder yet"
end
radio_button(method, tag_value, options = {}) click to toggle source
Calls superclass method
# File lib/lev/form_builder.rb, line 22
def radio_button(method, tag_value, options = {})
  options[:checked] = true if get_form_params_entry(method) == tag_value
  mark_error_if_present(method, options)
  super(method, tag_value, options)
end

Protected Instance Methods

get_form_params_entry(name) click to toggle source
# File lib/lev/form_builder.rb, line 34
def get_form_params_entry(name)
  @options[:params].present? ?
    (@options[:params][@object_name].present? ?
      @options[:params][@object_name][name] :
      nil) :
    nil
end
has_error?(name) click to toggle source
# File lib/lev/form_builder.rb, line 42
def has_error?(name)
  @options[:errors].present? ? @options[:errors].has_offending_input?([@object_name, name]) : false
end
mark_error_if_present(method, options) click to toggle source
# File lib/lev/form_builder.rb, line 51
def mark_error_if_present(method, options)
  if has_error?(method)
    options[:class] = [options[:class], Lev.configuration.form_error_class].compact.join(' ')
  end
end
set_value_if_available(method, options) click to toggle source
# File lib/lev/form_builder.rb, line 46
def set_value_if_available(method, options)
  value = get_form_params_entry(method)
  options[:value] ||= value if !value.nil?
end