#{description(description) || ' ' if type == 'check_box' }
#{label if type != 'check_box' }
#{@template.content_tag(:span, '*', :class => 'required_ind') if required }
#{prev_content}#{yield}#{content}
#{error_messages_for(method)}
#{description(description) if type != 'check_box'}
#{description(check_box_details) if type == 'check_box'}
}.html_safe
end
# generic container for all things form
def element(label = ' ', value = '', type = 'text_field', &block)
value += @template.capture(&block) if block_given?
%{
}}.join.html_safe
standard_field('radio_button', method, options) { radios }
elsif options && options[:value_name]
standard_field('radio_button', method, options) { super(method, tag_value) + %{}.html_safe}
else
standard_field('radio_button', method, options) { super(method, tag_value, options = {}) }
end
end
def select(method, choices, options = {}, html_options = {})
standard_field('select', method, options) { super(method, choices, options, html_options) }
end
def hidden_field(method, options = {}, html_options = {})
super(method, options)
end
def submit(value, options={}, &block)
cancel_link = @template.capture(&block) if block_given?
cancel_link ||= options[:cancel_url] ? ' or ' + options.delete(:cancel_url) : ''
if options[:show_ajax_loader]
options[:onclick] = "$(this).parent().next().css('display', 'block');$(this).parent().hide();"
end
if options[:image_button] == true
submit_id = Time.now.usec
out = @template.content_tag(:div,
%{
#{super(value, options.merge(:style=>'visibility:hidden;position: absolute', :id => submit_id)).html_safe}
#{value}
#{cancel_link.html_safe}
}.html_safe, :class => 'form_element submit_element').html_safe
else
out = @template.content_tag(:div, super(value, options) + cancel_link.html_safe, :class => 'form_element submit_element').html_safe
end
if options[:show_ajax_loader]
out << %{
#{options[:show_ajax_loader]}
}.html_safe
end
out.html_safe
end
def label_for(method, options)
label = options.delete(:label) || method.to_s.titleize.capitalize
""
end
def description(description)
"
#{description}
" unless description.nil?
end
def error_messages
if object && !object.errors.empty?
message = object.errors[:base].present? ? object.errors[:base]: 'There were some problems submitting this form. Please correct all the highlighted fields and try again'
@template.content_tag(:div, message, :class => 'form_error')
end
end
def error_messages_for(method)
if (object and object.respond_to?(:errors) and errors = object.errors[method])
"
#{errors.is_a?(Array) ? errors.first : errors}
"
else
''
end
end
def formatted_fields_for(record_or_name_or_array, *args, &block)
options = args.extract_options!
options.merge!(:builder => FormattedForm::Builder)
fields_for(record_or_name_or_array, *(args << options), &block)
end
end
end