Module: Rails4ClientSideValidations::ActionView::Helpers::FormHelper
- Defined in:
- lib/rails4_client_side_validations/action_view/form_helper.rb
Defined Under Namespace
Classes: Error
Instance Method Summary collapse
- #apply_form_for_options!(object_or_array, object, options) ⇒ Object
- #assign_script_to_content_for(name, script) ⇒ Object
- #fields_for(record_or_name_or_array, record_object = nil, options = {}, &block) ⇒ Object
- #form_for(record, *args, &block) ⇒ Object
Instance Method Details
#apply_form_for_options!(object_or_array, object, options) ⇒ Object
53 54 55 56 |
# File 'lib/rails4_client_side_validations/action_view/form_helper.rb', line 53 def (object_or_array, object, ) super [:html][:validate] = true if [:validate] end |
#assign_script_to_content_for(name, script) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/rails4_client_side_validations/action_view/form_helper.rb', line 46 def assign_script_to_content_for(name, script) if name && name != true content_for(name) { script.html_safe } true end end |
#fields_for(record_or_name_or_array, record_object = nil, options = {}, &block) ⇒ Object
58 59 60 61 62 |
# File 'lib/rails4_client_side_validations/action_view/form_helper.rb', line 58 def fields_for(record_or_name_or_array, record_object = nil, = {}, &block) output = super process_validators output end |
#form_for(record, *args, &block) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rails4_client_side_validations/action_view/form_helper.rb', line 5 def form_for(record, *args, &block) raise ArgumentError, "Missing block" unless block_given? = args. if [:validate] # Always turn off HTML5 Validations [:html] ||= {} [:html][:novalidate] = 'novalidate' case record when String, Symbol raise Rails4ClientSideValidations::ActionView::Helpers::FormHelper::Error, 'Using form_for(:name, @resource) is not supported with ClientSideValidations. Please use form_for(@resource, :as => :name) instead.' else object = record.is_a?(Array) ? record.last : record object_name = [:as] || model_name_from_record_or_class(object).param_key end end @validators = {} # Order matters here. Rails mutates the options object html_id = [:html][:id] if [:html] form = super(record, *(args << ), &block) [:id] = html_id if html_id process_validators builder = instantiate_builder(object_name, object, ) if object_name and object script = client_side_form_settings(object, , builder) # Because of the load order requirement above this sub is necessary # Would be nice to not do this script = insert_validators_into_script(script) if assign_script_to_content_for([:validate], script) form.html_safe else "#{form}#{script}".html_safe end end |