Module: ClientSideValidations::ActionView::Helpers::FormBuilder
- Defined in:
- lib/client_side_validations/action_view/form_builder.rb
Class Method Summary collapse
Instance Method Summary collapse
- #check_box(method, options = {}, checked_value = '1', unchecked_value = '0') ⇒ Object
- #client_side_form_settings(_options, form_helper) ⇒ Object
- #collection_select(method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
- #fields(scope = nil, model: nil, **options, &block) ⇒ Object
- #fields_for(record_name, record_object = nil, fields_options = {}, &block) ⇒ Object
- #file_field(method, options = {}) ⇒ Object
- #grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {}) ⇒ Object
- #initialize(object_name, object, template, options) ⇒ Object
- #radio_button(method, tag_value, options = {}) ⇒ Object
- #select(method, choices = nil, options = {}, html_options = {}, &block) ⇒ Object
- #time_zone_select(method, priority_zones = nil, options = {}, html_options = {}) ⇒ Object
- #validate(*attrs) ⇒ Object
Class Method Details
.prepended(base) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/client_side_validations/action_view/form_builder.rb', line 7 def self.prepended(base) (base.field_helpers - %i[label check_box radio_button fields_for fields hidden_field file_field]).each do |selector| base.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 # Cannot call super here, rewrite all def #{selector}(method, options = {}) # def text_field(method, options = {}) build_validation_options(method, options) # build_validation_options(method, options) options.delete(:validate) # options.delete(:validate) @template.send( # @template.send( #{selector.inspect}, # "text_field", @object_name, # @object_name, method, # method, objectify_options(options)) # objectify_options(options)) end # end RUBY_EVAL end end |
Instance Method Details
#check_box(method, options = {}, checked_value = '1', unchecked_value = '0') ⇒ Object
45 46 47 48 49 |
# File 'lib/client_side_validations/action_view/form_builder.rb', line 45 def check_box(method, = {}, checked_value = '1', unchecked_value = '0') (method, ) .delete(:validate) super end |
#client_side_form_settings(_options, form_helper) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/client_side_validations/action_view/form_builder.rb', line 29 def client_side_form_settings(, form_helper) { type: self.class.name, input_tag: error_field(form_helper, :span, 'input_tag'), label_tag: error_field(form_helper, :label, 'label_tag') } end |
#collection_select(method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
59 60 61 62 63 |
# File 'lib/client_side_validations/action_view/form_builder.rb', line 59 def collection_select(method, collection, value_method, text_method, = {}, = {}) (method, .merge(name: [:name])) .delete(:validate) super end |
#fields(scope = nil, model: nil, **options, &block) ⇒ Object
75 76 77 78 |
# File 'lib/client_side_validations/action_view/form_builder.rb', line 75 def fields(scope = nil, model: nil, **, &block) [:validate] ||= @options[:validate] if @options[:validate] && !.key?(:validate) super end |
#fields_for(record_name, record_object = nil, fields_options = {}, &block) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/client_side_validations/action_view/form_builder.rb', line 65 def fields_for(record_name, record_object = nil, = {}, &block) if record_object.is_a?(Hash) && record_object. = record_object record_object = nil end [:validate] ||= @options[:validate] if @options[:validate] && !.key?(:validate) super end |
#file_field(method, options = {}) ⇒ Object
80 81 82 83 84 |
# File 'lib/client_side_validations/action_view/form_builder.rb', line 80 def file_field(method, = {}) (method, ) .delete(:validate) super end |
#grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {}) ⇒ Object
86 87 88 89 90 |
# File 'lib/client_side_validations/action_view/form_builder.rb', line 86 def grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, = {}, = {}) (method, .merge(name: [:name])) .delete(:validate) super end |
#initialize(object_name, object, template, options) ⇒ Object
24 25 26 27 |
# File 'lib/client_side_validations/action_view/form_builder.rb', line 24 def initialize(object_name, object, template, ) super @options[:validators] = { object => {} } end |
#radio_button(method, tag_value, options = {}) ⇒ Object
92 93 94 95 96 |
# File 'lib/client_side_validations/action_view/form_builder.rb', line 92 def (method, tag_value, = {}) (method, ) .delete(:validate) super end |
#select(method, choices = nil, options = {}, html_options = {}, &block) ⇒ Object
98 99 100 101 102 |
# File 'lib/client_side_validations/action_view/form_builder.rb', line 98 def select(method, choices = nil, = {}, = {}, &block) (method, .merge(name: [:name])) .delete(:validate) super end |
#time_zone_select(method, priority_zones = nil, options = {}, html_options = {}) ⇒ Object
104 105 106 107 108 |
# File 'lib/client_side_validations/action_view/form_builder.rb', line 104 def time_zone_select(method, priority_zones = nil, = {}, = {}) (method, .merge(name: [:name])) .delete(:validate) super end |
#validate(*attrs) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/client_side_validations/action_view/form_builder.rb', line 37 def validate(*attrs) = attrs.pop if attrs.last.is_a?(Hash) (attrs.presence || @object._validators.keys).each do |attr| (attr, validate: ) end nil end |