Skip to content

Commit f784bc9

Browse files
committed
Alphabetize field methods
1 parent db59af7 commit f784bc9

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

lib/client_side_validations/action_view/form_builder.rb

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ def #{selector}(method, options = {}) # def text_field(method, options = {
2121
end
2222
end
2323

24+
def initialize(object_name, object, template, options)
25+
super(object_name, object, template, options)
26+
@options[:validators] = { object => {} }
27+
end
28+
2429
def client_side_form_settings(_options, form_helper)
2530
{
2631
type: self.class.to_s,
@@ -37,25 +42,24 @@ def validate(*attrs)
3742
nil
3843
end
3944

40-
def initialize(object_name, object, template, options)
41-
super(object_name, object, template, options)
42-
@options[:validators] = { object => {} }
45+
def check_box(method, options = {}, checked_value = '1', unchecked_value = '0')
46+
build_validation_options(method, options)
47+
options.delete(:validate)
48+
super(method, options, checked_value, unchecked_value)
4349
end
4450

45-
def fields_for(record_name, record_object = nil, fields_options = {}, &block)
46-
if record_object.is_a?(Hash) && record_object.extractable_options?
47-
fields_options = record_object
48-
record_object = nil
51+
%i[collection_check_boxes collection_radio_buttons].each do |method_name|
52+
define_method method_name do |method, collection, value_method, text_method, options = {}, html_options = {}, &block|
53+
build_validation_options(method, html_options.merge(name: options[:name]))
54+
html_options.delete(:validate)
55+
super(method, collection, value_method, text_method, options, html_options, &block)
4956
end
50-
51-
fields_options[:validate] ||= @options[:validate] if @options[:validate] && !fields_options.key?(:validate)
52-
super(record_name, record_object, fields_options, &block)
5357
end
5458

55-
def check_box(method, options = {}, checked_value = '1', unchecked_value = '0')
56-
build_validation_options(method, options)
57-
options.delete(:validate)
58-
super(method, options, checked_value, unchecked_value)
59+
def collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
60+
build_validation_options(method, html_options.merge(name: options[:name]))
61+
html_options.delete(:validate)
62+
super(method, collection, value_method, text_method, options, html_options)
5963
end
6064

6165
def radio_button(method, tag_value, options = {})
@@ -64,24 +68,20 @@ def radio_button(method, tag_value, options = {})
6468
super(method, tag_value, options)
6569
end
6670

67-
def select(method, choices = nil, options = {}, html_options = {}, &block)
68-
build_validation_options(method, html_options.merge(name: options[:name]))
69-
html_options.delete(:validate)
70-
super(method, choices, options, html_options, &block)
71-
end
71+
def fields_for(record_name, record_object = nil, fields_options = {}, &block)
72+
if record_object.is_a?(Hash) && record_object.extractable_options?
73+
fields_options = record_object
74+
record_object = nil
75+
end
7276

73-
def collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
74-
build_validation_options(method, html_options.merge(name: options[:name]))
75-
html_options.delete(:validate)
76-
super(method, collection, value_method, text_method, options, html_options)
77+
fields_options[:validate] ||= @options[:validate] if @options[:validate] && !fields_options.key?(:validate)
78+
super(record_name, record_object, fields_options, &block)
7779
end
7880

79-
%i[collection_check_boxes collection_radio_buttons].each do |method_name|
80-
define_method method_name do |method, collection, value_method, text_method, options = {}, html_options = {}, &block|
81-
build_validation_options(method, html_options.merge(name: options[:name]))
82-
html_options.delete(:validate)
83-
super(method, collection, value_method, text_method, options, html_options, &block)
84-
end
81+
def file_field(method, options = {})
82+
build_validation_options(method, options)
83+
options.delete(:validate)
84+
super(method, options)
8585
end
8686

8787
def grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {})
@@ -90,16 +90,16 @@ def grouped_collection_select(method, collection, group_method, group_label_meth
9090
super(method, collection, group_method, group_label_method, option_key_method, option_value_method, options, html_options)
9191
end
9292

93-
def time_zone_select(method, priority_zones = nil, options = {}, html_options = {})
93+
def select(method, choices = nil, options = {}, html_options = {}, &block)
9494
build_validation_options(method, html_options.merge(name: options[:name]))
9595
html_options.delete(:validate)
96-
super(method, priority_zones, options, html_options)
96+
super(method, choices, options, html_options, &block)
9797
end
9898

99-
def file_field(method, options = {})
100-
build_validation_options(method, options)
101-
options.delete(:validate)
102-
super(method, options)
99+
def time_zone_select(method, priority_zones = nil, options = {}, html_options = {})
100+
build_validation_options(method, html_options.merge(name: options[:name]))
101+
html_options.delete(:validate)
102+
super(method, priority_zones, options, html_options)
103103
end
104104

105105
private

0 commit comments

Comments
 (0)