Class: ActionValidator::FormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Defined in:
lib/action_validator/form_builder.rb

Overview

A custom FormBuilder class that renders inputs with all the necessary attributes for the ActionValidator Stimulus controller to work.

Instance Method Summary collapse

Instance Method Details

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

:nodoc:



58
59
60
61
62
63
# File 'lib/action_validator/form_builder.rb', line 58

def check_box(attribute, options = {}, checked_value = "1", unchecked_value = "0") # :nodoc:
  options[:data] ||= {}
  options[:data].merge!(input_data_options(attribute, options))

  super(attribute, options, checked_value, unchecked_value)
end

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

:nodoc:



42
43
44
# File 'lib/action_validator/form_builder.rb', line 42

def date_field(attribute, options = {}) # :nodoc:
  render_field(attribute, options) { super }
end

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

:nodoc:



65
66
67
# File 'lib/action_validator/form_builder.rb', line 65

def datetime_field(attribute, options = {}) # :nodoc:
  render_field(attribute, options) { super }
end

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

:nodoc:



69
70
71
# File 'lib/action_validator/form_builder.rb', line 69

def datetime_local_field(attribute, options = {}) # :nodoc:
  render_field(attribute, options) { super }
end

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

:nodoc:



50
51
52
# File 'lib/action_validator/form_builder.rb', line 50

def email_field(attribute, options = {}) # :nodoc:
  render_field(attribute, options) { super }
end

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

:nodoc:



15
16
17
18
19
20
21
# File 'lib/action_validator/form_builder.rb', line 15

def error(attribute, options = {}) # :nodoc:
  options[:data] ||= {}
  options[:data][ActionValidator::STIMULUS_SELECTORS[:target]] = :error
  options[:data][:attribute] = attribute

  @template.tag(:div, { **options, id: attribute })
end

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

:nodoc:



73
74
75
# File 'lib/action_validator/form_builder.rb', line 73

def file_field(attribute, options = {}) # :nodoc:
  render_field(attribute, options) { super }
end

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

:nodoc:



77
78
79
# File 'lib/action_validator/form_builder.rb', line 77

def hidden_field(attribute, options = {}) # :nodoc:
  render_field(attribute, options) { super }
end

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

:nodoc:



81
82
83
# File 'lib/action_validator/form_builder.rb', line 81

def month_field(attribute, options = {}) # :nodoc:
  render_field(attribute, options) { super }
end

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

:nodoc:



38
39
40
# File 'lib/action_validator/form_builder.rb', line 38

def number_field(attribute, options = {}) # :nodoc:
  render_field(attribute, options) { super }
end

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

:nodoc:



85
86
87
# File 'lib/action_validator/form_builder.rb', line 85

def password_field(attribute, options = {}) # :nodoc:
  render_field(attribute, options) { super }
end

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

:nodoc:



54
55
56
# File 'lib/action_validator/form_builder.rb', line 54

def phone_field(attribute, options = {}) # :nodoc:
  render_field(attribute, options) { super }
end

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

:nodoc:



89
90
91
# File 'lib/action_validator/form_builder.rb', line 89

def radio_button(attribute, options = {}) # :nodoc:
  render_field(attribute, options) { super }
end

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

:nodoc:



93
94
95
# File 'lib/action_validator/form_builder.rb', line 93

def range_field(attribute, options = {}) # :nodoc:
  render_field(attribute, options) { super }
end

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

:nodoc:



97
98
99
# File 'lib/action_validator/form_builder.rb', line 97

def rich_text_area(attribute, options = {}) # :nodoc:
  render_field(attribute, options) { super }
end

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

:nodoc:



101
102
103
# File 'lib/action_validator/form_builder.rb', line 101

def search_field(attribute, options = {}) # :nodoc:
  render_field(attribute, options) { super }
end

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

:nodoc:



8
9
10
11
12
13
# File 'lib/action_validator/form_builder.rb', line 8

def select(method, choices = nil, options = {}, html_options = {}, &block) # :nodoc:
  options[:data] ||= {}
  options[:data].merge!(input_data_options(attribute, options))

  super
end

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

:nodoc:



23
24
25
26
27
28
29
30
31
32
# File 'lib/action_validator/form_builder.rb', line 23

def submit(value = nil, options = {}, &block) # :nodoc:
  if value.is_a?(Hash)
    options = value
    value = nil
  end
  options[:data] ||= {}
  options[:data].merge!("action-validator--form-target" => :submit)

  super
end

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

:nodoc:



105
106
107
# File 'lib/action_validator/form_builder.rb', line 105

def telephone_field(attribute, options = {}) # :nodoc:
  render_field(attribute, options) { super }
end

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

:nodoc:



46
47
48
# File 'lib/action_validator/form_builder.rb', line 46

def text_area(attribute, options = {}) # :nodoc:
  render_field(attribute, options) { super }
end

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

:nodoc:



34
35
36
# File 'lib/action_validator/form_builder.rb', line 34

def text_field(attribute, options = {}) # :nodoc:
  render_field(attribute, options) { super }
end

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

:nodoc:



109
110
111
# File 'lib/action_validator/form_builder.rb', line 109

def time_field(attribute, options = {}) # :nodoc:
  render_field(attribute, options) { super }
end

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

:nodoc:



113
114
115
# File 'lib/action_validator/form_builder.rb', line 113

def url_field(attribute, options = {}) # :nodoc:
  render_field(attribute, options) { super }
end

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

:nodoc:



117
118
119
# File 'lib/action_validator/form_builder.rb', line 117

def week_field(attribute, options = {}) # :nodoc:
  render_field(attribute, options) { super }
end