Module: TblForm::ActionViewExtensions::FormHelper

Defined in:
lib/tbl_form/form_helper.rb

Overview

This modules create simple form wrappers around default form_for, fields_for and remote_form_for.

Example:

ms_form_for @user do |f|
  f.input :name, :hint => 'My hint'
end

Constant Summary collapse

FIELD_ERROR_PROC =

Override the default ActiveRecordHelper behaviour of wrapping the input. This gets taken care of semantically by adding an error class to the wrapper tag containing the input.

proc do |html_tag, instance_tag|
  html_tag
end
@@default_field_error_proc =
nil

Instance Method Summary collapse

Instance Method Details

#table_set(summary = nil, *args, &block) ⇒ Object



53
54
55
56
57
# File 'lib/tbl_form/form_helper.rb', line 53

def table_set(summary = nil, *args, &block)
  options = args.extract_options!
  content = capture(&block)
  "<table class=\"table_set\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" summary=\"#{summary}\">\n".html_safe + content + "</table>\n".html_safe
end

#tbl_display(label = '', text = '', options = {}) ⇒ Object



65
66
67
68
69
70
# File 'lib/tbl_form/form_helper.rb', line 65

def tbl_display(label = '', text = '', options = {})
  options = options.to_options!
  fieldoptions = options.delete(:fieldoptions)
  labeloptions = options.delete(:labeloptions)
  (:tr, (:th, label, labeloptions) + (:td, text, options), fieldoptions)
end

#tbl_display_form(summary = nil, *args, &block) ⇒ Object



59
60
61
62
63
# File 'lib/tbl_form/form_helper.rb', line 59

def tbl_display_form(summary = nil, *args, &block)
  options = args.extract_options!
  content = capture(&block)
  "<table class=\"tbl_display_form\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" summary=\"#{summary}\">\n".html_safe + content + "</table>\n".html_safe
end

#tbl_wrap(label = '', *args, &block) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/tbl_form/form_helper.rb', line 72

def tbl_wrap(label = '', *args, &block)
  options = args.extract_options!
  content = capture(&block)

  #fieldstyle = options.delete(:fieldstyle) || ""
  #fieldstyle += " width: #{options.delete(:fieldwidth) || "100%"};".html_safe
  #fieldextra = options.delete(:fieldextra) || ""

  forvalue = options.delete(:for) || ""
  label = options.delete(:label) || "#{label.to_s.titleize}".html_safe
  hint = options.delete(:hint) || ""
  label = label + "<span class=\"ms_hint\">#{hint}</span>".html_safe unless hint.blank?

  (:tr, (:th, label, options) + (:td, content, options), options)
end

#with_custom_field_error_proc(&block) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/tbl_form/form_helper.rb', line 25

def with_custom_field_error_proc(&block)
  @@default_field_error_proc = ::ActionView::Base.field_error_proc
  ::ActionView::Base.field_error_proc = FIELD_ERROR_PROC
  result = yield
  ::ActionView::Base.field_error_proc = @@default_field_error_proc
  result
end