Module: Trestle::FormHelper
- Defined in:
- app/helpers/trestle/form_helper.rb
Constant Summary collapse
- IDENTITY_FIELD_ERROR_PROC =
Proc.new { |html_tag, instance| html_tag }
- DEFAULT_FORM_CONTROLLERS =
%w(keyboard-submit form-loading form-error)
Instance Method Summary collapse
- #form ⇒ Object
- #render_sidebar_as_tab? ⇒ Boolean
- #sidebar(&block) ⇒ Object
- #trestle_form_for(instance, options = {}, &block) ⇒ Object
- #with_form(form) ⇒ Object
- #with_identity_field_error_proc ⇒ Object
Instance Method Details
#form ⇒ Object
36 37 38 |
# File 'app/helpers/trestle/form_helper.rb', line 36 def form @_trestle_form end |
#render_sidebar_as_tab? ⇒ Boolean
44 45 46 |
# File 'app/helpers/trestle/form_helper.rb', line 44 def modal_request? && content_for?(:sidebar) end |
#sidebar(&block) ⇒ Object
40 41 42 |
# File 'app/helpers/trestle/form_helper.rb', line 40 def (&block) content_for(:sidebar, &block) end |
#trestle_form_for(instance, options = {}, &block) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/helpers/trestle/form_helper.rb', line 6 def trestle_form_for(instance, ={}, &block) [:builder] ||= Form::Builder [:as] ||= admin.parameter_name [:data] ||= {} [:data][:controller] = (DEFAULT_FORM_CONTROLLERS + Array([:data][:controller])).join(" ") form_for(instance, ) do |f| with_identity_field_error_proc do with_form(f) { yield f } end end end |
#with_form(form) ⇒ Object
20 21 22 23 24 25 |
# File 'app/helpers/trestle/form_helper.rb', line 20 def with_form(form) @_trestle_form = form yield form if block_given? ensure @_trestle_form = nil end |
#with_identity_field_error_proc ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'app/helpers/trestle/form_helper.rb', line 27 def with_identity_field_error_proc original_field_error_proc = ::ActionView::Base.field_error_proc ::ActionView::Base.field_error_proc = IDENTITY_FIELD_ERROR_PROC yield if block_given? ensure ::ActionView::Base.field_error_proc = original_field_error_proc end |