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 =
based on what is done in formtastic github.com/justinfrench/formtastic/blob/master/lib/formtastic.rb#L1706
nil
Instance Method Summary collapse
- #table_set(summary = nil, *args, &block) ⇒ Object
- #tbl_display(label = '', text = '', options = {}) ⇒ Object
- #tbl_display_form(summary = nil, *args, &block) ⇒ Object
- #tbl_wrap(label = '', *args, &block) ⇒ Object
- #with_custom_field_error_proc(&block) ⇒ Object
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) = args. 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 = '', = {}) = . = .delete(:fieldoptions) = .delete(:labeloptions) content_tag(:tr, content_tag(:th, label, ) + content_tag(:td, text, ), ) 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) = args. 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) = args. content = capture(&block) #fieldstyle = options.delete(:fieldstyle) || "" #fieldstyle += " width: #{options.delete(:fieldwidth) || "100%"};".html_safe #fieldextra = options.delete(:fieldextra) || "" forvalue = .delete(:for) || "" label = .delete(:label) || "#{label.to_s.titleize}".html_safe hint = .delete(:hint) || "" label = label + "<span class=\"ms_hint\">#{hint}</span>".html_safe unless hint.blank? content_tag(:tr, content_tag(:th, label, ) + content_tag(:td, content, ), ) 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 |