Module: MsForm::ActionViewExtensions::FormHelper
- Defined in:
- lib/ms_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
- #ms_display(label = '', value = '', options = {}) ⇒ Object
- #ms_display_form(legend = nil, *args, &block) ⇒ Object
- #ms_wrap(label = '', *args, &block) ⇒ Object
- #with_custom_field_error_proc(&block) ⇒ Object
Instance Method Details
#ms_display(label = '', value = '', options = {}) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/ms_form/form_helper.rb', line 60 def ms_display(label = '', value = '', = {}) fieldstyle = .delete(:fieldstyle) || "" fieldstyle += " width: #{.delete(:fieldwidth) || "100%"};" fieldextra = .delete(:fieldextra) || "" "<div class=\"ms_field\", style=\"#{fieldstyle}\"><div class=\"ms_field_label\"><span class=\"ms_label\">#{fieldextra}#{label}</span></div><span class=\"ms_field_content\">#{value}</span></div>".html_safe end |
#ms_display_form(legend = nil, *args, &block) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/ms_form/form_helper.rb', line 53 def ms_display_form(legend = nil, *args, &block) = args. content = capture(&block) "<div class=\"ms_display_form\">".html_safe + content + "</div>".html_safe end |
#ms_wrap(label = '', *args, &block) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ms_form/form_helper.rb', line 67 def ms_wrap(label = '', *args, &block) = args. content = capture(&block) fieldstyle = .delete(:fieldstyle) || "" fieldstyle += " width: #{.delete(:fieldwidth) || "100%"};" fieldextra = .delete(:fieldextra) || "" forvalue = .delete(:for) || "" text = .delete(:label) || "#{label.to_s.titleize}" hint = .delete(:hint) || "" text = text + "<span class=\"ms_hint\">#{hint}</span>" unless hint.blank? "<div class=\"ms_field\", style=\"#{fieldstyle}\"><div class=\"ms_field_label\">#{fieldextra}<label class=\"ms_label\" for=\"#{forvalue}\">#{text}</label></div>".html_safe + content + "</div>".html_safe end |
#with_custom_field_error_proc(&block) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/ms_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 |