Method: CmsApplicationHelper#form_icons

Defined in:
app/helpers/cms_application_helper.rb

#form_icons(object_name, method_name, options = {}) ⇒ Object

Takes object_name and method_name as arguments (like other form helpers, such as text_field) and returns html containing form_error.gif and form_loading.gif. If there are no errors for the given field, form_error.gif is hidden using style=“display: none”. If there are errors, form_error.gif is shown, and its hover text lists the errors.



612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
# File 'app/helpers/cms_application_helper.rb', line 612

def form_icons(object_name, method_name, options = {})
  object_name = object_name.to_s
  method_name = method_name.to_s
  
  ret = ''
  errors = []
  
  instance_variable_get("@#{object_name}").errors.each do |attr, msg|
    errors << msg if attr == method_name
  end
  
  options[:style] ||= ''
  
  if errors.size == 0
    options[:style] << 'display: none;'
  end
  
  ret << "<div id=\"#{object_name}_#{method_name}_error\" class=\"form-error\""
  ret << " style=\"#{options[:style]}\"" unless options[:style].blank?
  if errors.size > 0
    ret << " title=\"#{h errors.join('; ')}\""
  end
  ret << '><img src="/assets/interface/form_error.gif" width="17" height="17" border="0" />'
  ret << '</div>'
  
  ret << "<div id=\"#{object_name}_#{method_name}_loading\" class=\"form-loading\" style=\"display: none;\">"
  ret << image_tag("interface/form_loading.gif", size: '16x16', border: 0, style: "margin: 0 1px 1px 0;")
  ret << "</div>"
  
  if errors.size > 0 && options[:display_messages]
    options[:message_separator] ||= '<br/>'
    ret << "<div id=\"#{object_name}_#{method_name}_error_messages\" class=\"form-error-messages\">"
    ret << errors.join(options[:message_separator])
    ret << "</div>"
  end
  
  ret
end