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 }

Instance Method Summary collapse

Instance Method Details

#formObject



35
36
37
# File 'app/helpers/trestle/form_helper.rb', line 35

def form
  @_trestle_form
end

#render_sidebar_as_tab?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'app/helpers/trestle/form_helper.rb', line 43

def render_sidebar_as_tab?
  dialog_request? && content_for?(:sidebar)
end


39
40
41
# File 'app/helpers/trestle/form_helper.rb', line 39

def sidebar(&block)
  content_for(:sidebar, &block)
end

#trestle_form_for(instance, options = {}, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/helpers/trestle/form_helper.rb', line 5

def trestle_form_for(instance, options={}, &block)
  options[:builder] ||= Form::Builder
  options[:as] ||= admin.parameter_name

  options[:data] ||= {}
  options[:data].reverse_merge!(remote: true, type: :html, behavior: "trestle-form", turbolinks: false)

  form_for(instance, options) do |f|
    with_identity_field_error_proc do
      with_form(f) { yield f }
    end
  end
end

#with_form(form) ⇒ Object



19
20
21
22
23
24
# File 'app/helpers/trestle/form_helper.rb', line 19

def with_form(form)
  @_trestle_form = form
  yield form if block_given?
ensure
  @_trestle_form = nil
end

#with_identity_field_error_procObject



26
27
28
29
30
31
32
33
# File 'app/helpers/trestle/form_helper.rb', line 26

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