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_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 23 |
# 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 hidden_field file_field]).each do |selector| base.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 def #{selector}(method, options = {}) build_validation_options(method, options) options.delete(:validate) # Cannot call super here, override the whole method @template.send( # @template.send( #{selector.inspect}, # "text_field", @object_name, # @object_name, method, # method, objectify_options(options)) # objectify_options(options)) end RUBY_EVAL end end |
Instance Method Details
#check_box(method, options = {}, checked_value = '1', unchecked_value = '0') ⇒ Object
56 57 58 59 60 |
# File 'lib/client_side_validations/action_view/form_builder.rb', line 56 def check_box(method, = {}, checked_value = '1', unchecked_value = '0') (method, ) .delete(:validate) super(method, , checked_value, unchecked_value) end |
#client_side_form_settings(_options, form_helper) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/client_side_validations/action_view/form_builder.rb', line 25 def client_side_form_settings(, form_helper) { type: self.class.to_s, input_tag: form_helper.class.field_error_proc.call(%(<span id="input_tag" />), Struct.new(:error_message, :tag_id).new([], '')), label_tag: form_helper.class.field_error_proc.call(%(<label id="label_tag" />), Struct.new(:error_message, :tag_id).new([], '')) } end |
#collection_select(method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
74 75 76 77 78 |
# File 'lib/client_side_validations/action_view/form_builder.rb', line 74 def collection_select(method, collection, value_method, text_method, = {}, = {}) (method, .merge(name: [:name])) .delete(:validate) super(method, collection, value_method, text_method, , ) end |
#fields_for(record_name, record_object = nil, fields_options = {}, &block) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/client_side_validations/action_view/form_builder.rb', line 46 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(record_name, record_object, , &block) end |
#file_field(method, options = {}) ⇒ Object
100 101 102 103 104 |
# File 'lib/client_side_validations/action_view/form_builder.rb', line 100 def file_field(method, = {}) (method, ) .delete(:validate) super(method, ) end |
#grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {}) ⇒ Object
88 89 90 91 92 |
# File 'lib/client_side_validations/action_view/form_builder.rb', line 88 def grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, = {}, = {}) (method, .merge(name: [:name])) .delete(:validate) super(method, collection, group_method, group_label_method, option_key_method, option_value_method, , ) end |
#initialize(object_name, object, template, options) ⇒ Object
41 42 43 44 |
# File 'lib/client_side_validations/action_view/form_builder.rb', line 41 def initialize(object_name, object, template, ) super(object_name, object, template, ) @options[:validators] = { object => {} } end |
#radio_button(method, tag_value, options = {}) ⇒ Object
62 63 64 65 66 |
# File 'lib/client_side_validations/action_view/form_builder.rb', line 62 def (method, tag_value, = {}) (method, ) .delete(:validate) super(method, tag_value, ) end |
#select(method, choices = nil, options = {}, html_options = {}, &block) ⇒ Object
68 69 70 71 72 |
# File 'lib/client_side_validations/action_view/form_builder.rb', line 68 def select(method, choices = nil, = {}, = {}, &block) (method, .merge(name: [:name])) .delete(:validate) super(method, choices, , , &block) end |
#time_zone_select(method, priority_zones = nil, options = {}, html_options = {}) ⇒ Object
94 95 96 97 98 |
# File 'lib/client_side_validations/action_view/form_builder.rb', line 94 def time_zone_select(method, priority_zones = nil, = {}, = {}) (method, .merge(name: [:name])) .delete(:validate) super(method, priority_zones, , ) end |
#validate(*attrs) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/client_side_validations/action_view/form_builder.rb', line 33 def validate(*attrs) = attrs.pop if attrs.last.is_a?(Hash) (attrs.presence || @object._validators.keys).each do |attr| (attr, validate: ) end nil end |