From b4fcb1281c5a632378cbff771f1de1aaf5c816cd Mon Sep 17 00:00:00 2001 From: Isaac Sloan Date: Sat, 24 Nov 2018 23:24:22 -0700 Subject: [PATCH] multipart option for forms --- spec/jasper_helpers/forms_spec.cr | 9 +++++++++ src/jasper_helpers/forms.cr | 1 + 2 files changed, 10 insertions(+) diff --git a/spec/jasper_helpers/forms_spec.cr b/spec/jasper_helpers/forms_spec.cr index 389517d..6e6d0ee 100644 --- a/spec/jasper_helpers/forms_spec.cr +++ b/spec/jasper_helpers/forms_spec.cr @@ -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 = %(
) + + result.should eq(expected) + end end describe "#hidden_field" do diff --git a/src/jasper_helpers/forms.cr b/src/jasper_helpers/forms.cr index 8559a0c..21b4b6e 100644 --- a/src/jasper_helpers/forms.cr +++ b/src/jasper_helpers/forms.cr @@ -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)