Skip to content

Commit

Permalink
Fix file_field helper
Browse files Browse the repository at this point in the history
File fields automatically add `enctype="multipart/form-data"` attribute
to `<form>` tags. CSV was treating `file_field` as all other fields, so
`self.multipart = true` was skipped

Fix: #694
  • Loading branch information
tagliala committed Feb 6, 2017
1 parent b4cbeb9 commit 8fe3406
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion lib/client_side_validations/action_view/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module ActionView
module Helpers
module FormBuilder
def self.prepended(base)
(base.field_helpers.map(&:to_s) - %w(apply_form_for_options! label check_box radio_button fields_for hidden_field)).each do |selector|
(base.field_helpers - %i(label check_box radio_button fields_for hidden_field file_field)).each do |selector|
base.class_eval <<-RUBY_EVAL
def #{selector}(method, options = {})
build_validation_options(method, options)
Expand Down Expand Up @@ -90,6 +90,12 @@ def time_zone_select(method, priority_zones = nil, options = {}, html_options =
super(method, priority_zones, options, html_options)
end

def file_field(method, options = {})
build_validation_options(method, options)
options.delete(:validate)
super(method, options)
end

private

def build_validation_options(method, options = {})
Expand Down
2 changes: 1 addition & 1 deletion test/action_view/cases/test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_password_field
end

def test_file_field
form_for(@post, validate: true, html: { multipart: true }) do |f|
form_for(@post, validate: true) do |f|
concat f.file_field(:cost)
end

Expand Down
2 changes: 1 addition & 1 deletion test/action_view/cases/test_legacy_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_password_field
end

def test_file_field
form_for(@post, html: { multipart: true }) do |f|
form_for(@post) do |f|
concat f.file_field(:cost)
end

Expand Down

0 comments on commit 8fe3406

Please sign in to comment.