Class: PagesCore::FormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Includes:
ActionView::Helpers::TagHelper
Defined in:
app/helpers/pages_core/form_builder.rb

Direct Known Subclasses

Admin::FormBuilder

Instance Method Summary collapse

Instance Method Details

#field_with_label(attr, str, label = nil) ⇒ Object



5
6
7
8
9
# File 'app/helpers/pages_core/form_builder.rb', line 5

def field_with_label(attr, str, label = nil)
  classes = ["field"]
  classes << "field-with-errors" if object.errors[attr].any?
  (:div, label_for(attr, label) + str, class: classes.join(" "))
end

#image_file_field(attribute, options = {}) ⇒ Object



19
20
21
# File 'app/helpers/pages_core/form_builder.rb', line 19

def image_file_field(attribute, options = {})
  safe_join [image_file_preview(attribute), file_field(attribute, options)]
end

#image_file_preview(attribute) ⇒ Object



11
12
13
14
15
16
17
# File 'app/helpers/pages_core/form_builder.rb', line 11

def image_file_preview(attribute)
  return "" unless object.send(attribute) &&
                   !object.send(attribute).new_record?
  (
    :p, @template.dynamic_image_tag(object.send(attribute), size: "120x100")
  )
end

#label_and_errors(attribute, label_text) ⇒ Object



23
24
25
26
27
# File 'app/helpers/pages_core/form_builder.rb', line 23

def label_and_errors(attribute, label_text)
  return label_text unless object.errors[attribute].any?
  error = (:span, object.errors[attribute].first, class: "error")
  safe_join([label_text, error], " ")
end

#label_for(attribute, label_text = nil) ⇒ Object



29
30
31
32
33
# File 'app/helpers/pages_core/form_builder.rb', line 29

def label_for(attribute, label_text = nil)
  label_text ||= object.class.human_attribute_name(attribute)
  ("label", label_and_errors(attribute, label_text),
              for: [object.class.to_s.underscore, attribute].join("_"))
end

#labelled_check_box(attr, label = nil, options = {}, checked = "1", unchecked = "0") ⇒ Object



35
36
37
38
39
40
41
# File 'app/helpers/pages_core/form_builder.rb', line 35

def labelled_check_box(
  attr, label = nil, options = {}, checked = "1", unchecked = "0"
)
  labelled_field(attr, label, options) do |opts|
    check_box(attr, opts, checked, unchecked)
  end
end

#labelled_country_select(attr, label = nil, priority = {}, opts = {}, html_opts = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/helpers/pages_core/form_builder.rb', line 43

def labelled_country_select(
  attr, label = nil, priority = {}, opts = {}, html_opts = {}
)
  if priority.is_a?(Hash)
    return labelled_field(attr, label, priority) do |options|
      country_select(attr, options, opts, html_opts)
    end
  end
  labelled_field(attr, label, opts) do |options|
    country_select(attr, priority, options, html_opts)
  end
end

#labelled_date_select(attribute, label_text = nil, options = {}) ⇒ Object



56
57
58
59
60
# File 'app/helpers/pages_core/form_builder.rb', line 56

def labelled_date_select(attribute, label_text = nil, options = {})
  labelled_field(attribute, label_text, options) do |opts|
    date_select(attribute, opts)
  end
end

#labelled_datetime_select(attribute, label_text = nil, options = {}) ⇒ Object



62
63
64
65
66
# File 'app/helpers/pages_core/form_builder.rb', line 62

def labelled_datetime_select(attribute, label_text = nil, options = {})
  labelled_field(attribute, label_text, options) do |opts|
    datetime_select(attribute, opts)
  end
end

#labelled_file_field(attribute, label_text = nil, options = {}) ⇒ Object



68
69
70
71
72
# File 'app/helpers/pages_core/form_builder.rb', line 68

def labelled_file_field(attribute, label_text = nil, options = {})
  labelled_field(attribute, label_text, options) do |opts|
    file_field(attribute, opts)
  end
end

#labelled_image_file_field(attribute, label_text = nil, options = {}) ⇒ Object



74
75
76
77
78
# File 'app/helpers/pages_core/form_builder.rb', line 74

def labelled_image_file_field(attribute, label_text = nil, options = {})
  labelled_field(attribute, label_text, options) do |opts|
    image_file_field(attribute, opts)
  end
end

#labelled_password_field(attribute, label_text = nil, options = {}) ⇒ Object



80
81
82
83
84
# File 'app/helpers/pages_core/form_builder.rb', line 80

def labelled_password_field(attribute, label_text = nil, options = {})
  labelled_field(attribute, label_text, options) do |opts|
    password_field(attribute, opts)
  end
end

#labelled_select(attribute, choices, label_text = nil, options = {}) ⇒ Object



86
87
88
89
90
# File 'app/helpers/pages_core/form_builder.rb', line 86

def labelled_select(attribute, choices, label_text = nil, options = {})
  labelled_field(attribute, label_text, options) do |opts|
    select(attribute, choices, opts)
  end
end

#labelled_text_area(attribute, label_text = nil, options = {}) ⇒ Object



92
93
94
95
96
# File 'app/helpers/pages_core/form_builder.rb', line 92

def labelled_text_area(attribute, label_text = nil, options = {})
  labelled_field(attribute, label_text, options) do |opts|
    text_area(attribute, opts)
  end
end

#labelled_text_field(attribute, label_text = nil, options = {}) ⇒ Object



98
99
100
101
102
# File 'app/helpers/pages_core/form_builder.rb', line 98

def labelled_text_field(attribute, label_text = nil, options = {})
  labelled_field(attribute, label_text, options) do |opts|
    text_field(attribute, opts)
  end
end

#labelled_time_select(attribute, label_text = nil, options = {}) ⇒ Object



104
105
106
107
108
# File 'app/helpers/pages_core/form_builder.rb', line 104

def labelled_time_select(attribute, label_text = nil, options = {})
  labelled_field(attribute, label_text, options) do |opts|
    time_select(attribute, opts)
  end
end