Class: Arara::FormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Includes:
ActionView::Helpers::FormTagHelper
Defined in:
app/components/arara/form_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#templateObject (readonly)

Returns the value of attribute template.



3
4
5
# File 'app/components/arara/form_builder.rb', line 3

def template
  @template
end

Instance Method Details

#check_box(method, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object



53
54
55
56
57
58
59
60
# File 'app/components/arara/form_builder.rb', line 53

def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
  options.deep_stringify_keys!  
  options["label"] = options.fetch("label") { build_label(method, options) }
  # options["has_error"] = has_errors_for?(method)
  # options["helper_text"] = errors_for(method).join(", ")

  Tags::CheckBox.new(object_name, method, self, checked_value, unchecked_value, objectify_options(options)).render
end

#chip_choice(method, options = {}, &block) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'app/components/arara/form_builder.rb', line 21

def chip_choice(method, options = {}, &block)
  options.deep_stringify_keys!
  options["variant"] = :choice

  checked_value = options[:value].to_s
  unchecked_value = 0
  options[:include_hidden] = false

  Tags::ChipChoice.new(object_name, method, self, checked_value, unchecked_value, objectify_options(options), &block).render
end

#chip_filter(method, options = {}, &block) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'app/components/arara/form_builder.rb', line 41

def chip_filter(method, options = {}, &block)
  options.deep_stringify_keys!
  options["variant"] = :filter

  checked_value = options[:value].to_s
  unchecked_value = 0
  options[:include_hidden] = true
  options[:multiple] = true

  Tags::ChipChoice.new(object_name, method, self, checked_value, unchecked_value, objectify_options(options), &block).render
end

#chipset_choice(method, options = {}, &block) ⇒ Object



12
13
14
15
16
17
18
19
# File 'app/components/arara/form_builder.rb', line 12

def chipset_choice(method, options = {}, &block)
  options.deep_stringify_keys!
  options["variant"] = :choice
  options[:data] ||= {}
  options[:data][:controller] = "rails-chip-set-choice"

  Tags::Chipset.new(object_name, method, self, objectify_options(options), &block).render
end

#chipset_filter(method, options = {}, &block) ⇒ Object



32
33
34
35
36
37
38
39
# File 'app/components/arara/form_builder.rb', line 32

def chipset_filter(method, options = {}, &block)
  options.deep_stringify_keys!
  options["variant"] = :filter
  options[:data] ||= {}
  options[:data][:controller] = "rails-chip-set-filter"

  Tags::Chipset.new(object_name, method, self, objectify_options(options), &block).render
end

#country_select(method, priority_or_options = {}, options = {}, html_options = {}) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
# File 'app/components/arara/form_builder.rb', line 102

def country_select(method, priority_or_options = {}, options = {}, html_options = {})
  options.deep_stringify_keys!
  if Hash === priority_or_options
    html_options = options
    options = priority_or_options
  else
    options[:priority_countries] = priority_or_options
  end

  options["label"] = options.fetch("label") { build_label(method, options) }
  Tags::CountrySelect.new(object_name, method, self, objectify_options(options), @default_options.merge(html_options)).render
end

#label(method, options = {}) ⇒ Object



7
8
9
10
# File 'app/components/arara/form_builder.rb', line 7

def label(method, options = {})
  options.deep_stringify_keys!
  super(method, options)
end

#password_field(method, options = {}) ⇒ Object



71
72
73
74
75
76
77
78
79
# File 'app/components/arara/form_builder.rb', line 71

def password_field(method, options = {})
  options.deep_stringify_keys!
  options["label"] = options.fetch("label") { build_label(method, options) }
  options["has_error"] = has_errors_for?(method)
  options["helper_text"] = errors_for(method).join(", ")
  options["type"] = "password"

  Tags::PasswordField.new(object_name, method, self, objectify_options(options)).render
end

#radio_button(method, tag_value, options = {}) ⇒ Object



97
98
99
100
# File 'app/components/arara/form_builder.rb', line 97

def radio_button(method, tag_value, options = {})
  options.deep_stringify_keys!
  Tags::RadioButton.new(object_name, method, self, tag_value, objectify_options(options)).render
end

#select(method, choices = nil, options = {}, html_options = {}, &block) ⇒ Object



90
91
92
93
94
95
# File 'app/components/arara/form_builder.rb', line 90

def select(method, choices = nil, options = {}, html_options = {}, &block)
  options.deep_stringify_keys!
  options["label"] = options.fetch("label") { build_label(method, options) }

  Tags::Select.new(object_name, method, self, choices, objectify_options(options), objectify_options(html_options), &block).render
end

#submit(value = nil, options = {}) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
# File 'app/components/arara/form_builder.rb', line 115

def submit(value = nil, options = {})
  options.deep_stringify_keys!
  value, options = nil, value if value.is_a?(Hash)
  value ||= submit_default_value
  
  options = options.deep_stringify_keys
  tag_options = { "type" => "submit", "name" => "commit", "value" => value }.update(options)
  set_default_disable_with value, tag_options

  @template.render(ButtonComponent, tag_options.symbolize_keys)
end

#text_area(method, options = {}) ⇒ Object



81
82
83
84
85
86
87
88
# File 'app/components/arara/form_builder.rb', line 81

def text_area(method, options = {})
  options.deep_stringify_keys!
  options["label"] = options.fetch("label") { build_label(method, options) }
  options["has_error"] = has_errors_for?(method)
  options["helper_text"] = errors_for(method).join(", ")

  Tags::TextArea.new(object_name, method, self, objectify_options(options)).render
end

#text_field(method, options = {}) ⇒ Object



62
63
64
65
66
67
68
69
# File 'app/components/arara/form_builder.rb', line 62

def text_field(method, options = {})
  options.deep_stringify_keys!
  options["label"] = options.fetch("label") { build_label(method, options) }
  options["has_error"] = has_errors_for?(method)
  options["helper_text"] ||= errors_for(method).join(", ")

  Tags::TextField.new(object_name, method, self, objectify_options(options)).render
end