class Formative::FormBuilder
Public Instance Methods
check_box(field_name, options = {}, checked_value = "1", unchecked_value = "0")
click to toggle source
Calls superclass method
# File lib/formative/form_builder.rb, line 12 def check_box(field_name, options = {}, checked_value = "1", unchecked_value = "0") content_tag(wrapper(options), super + field_label(field_name, options) + unit(options) + hint(options).html_safe, :class => wrapper_class('check_box', field_name)) end
Private Instance Methods
content_tag(tag, content, *args)
click to toggle source
# File lib/formative/form_builder.rb, line 18 def content_tag(tag, content, *args) return content unless tag @template.content_tag(tag, content, *args) end
field_label(field_name, *args)
click to toggle source
# File lib/formative/form_builder.rb, line 23 def field_label(field_name, *args) options = args.extract_options! return '' if options[:label] == false options.reverse_merge!(:required => field_required?(field_name)) options[:label_class] = 'required' if options[:required] label(field_name, options[:label], :class => options[:label_class]) end
field_required?(field_name)
click to toggle source
# File lib/formative/form_builder.rb, line 43 def field_required?(field_name) object.class.reflect_on_validations_for(field_name).map(&:macro).include?(:validates_presence_of) if object.class.respond_to?(:reflect_on_validations_for) end
filter_custom_options(options)
click to toggle source
# File lib/formative/form_builder.rb, line 60 def filter_custom_options(options) options.except(:label, :required, :label_class, :wrapper, :hint, :unit) end
hint(*args)
click to toggle source
# File lib/formative/form_builder.rb, line 31 def hint(*args) options = args.extract_options! return '' if options[:hint] == false || options[:hint].blank? content_tag(:span, options[:hint], :class => 'hint') end
objectify_options(options)
click to toggle source
Calls superclass method
# File lib/formative/form_builder.rb, line 56 def objectify_options(options) filter_custom_options(super) end
unit(*args)
click to toggle source
# File lib/formative/form_builder.rb, line 37 def unit(*args) options = args.extract_options! return '' if options[:unit] == false || options[:unit].blank? content_tag(:span, options[:unit], :class => 'unit') end
wrapper(*args)
click to toggle source
# File lib/formative/form_builder.rb, line 47 def wrapper(*args) options = args.extract_options! options[:wrapper] == false ? nil : (options[:wrapper] || :p) end
wrapper_class(method_name, field_name)
click to toggle source
# File lib/formative/form_builder.rb, line 52 def wrapper_class(method_name, field_name) "field #{method_name.to_s.dasherize} #{field_name.to_s.dasherize}" end