Skip to content

Commit

Permalink
multipart option for forms
Browse files Browse the repository at this point in the history
  • Loading branch information
elorest committed Nov 25, 2018
1 parent c089a35 commit b4fcb12
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions spec/jasper_helpers/forms_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ describe JasperHelpers::Forms do

result.should eq(expected)
end

it "sets up form for multipart" do
result = form(method: :post, action: "/test/1", id: "myForm", multipart: true) do
text_field(:name)
end
expected = %(<form action="/test/1" id="myForm" multipart="true" method="post" enctype="multipart/form-data"><input type="text" name="name" id="name"/></form>)

result.should eq(expected)
end
end

describe "#hidden_field" do
Expand Down
1 change: 1 addition & 0 deletions src/jasper_helpers/forms.cr
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module JasperHelpers::Forms
# form
def form(method = :post, **options : Object, &block)
options_hash = Kit.safe_hash(options, {:method => (method == :get ? :get : :post)})
options_hash[:enctype] = "multipart/form-data" if options_hash[:multipart]? == true
content(element_name: :form, options: options_hash) do
String.build do |str|
str << hidden_field(name: "_method", value: method) unless [:get, :post].includes?(method)
Expand Down

0 comments on commit b4fcb12

Please sign in to comment.