rubymonolith / superform

Build highly customizable forms in Rails
MIT License
263 stars 14 forks source link

Support form `enctype` attribute for file inputs #3

Closed henri42 closed 7 months ago

henri42 commented 10 months ago

Hello,

I am in the process of starting a Rails project using Phlex and Superform. In my project, I need to upload files to the server. However, I've noticed that Superform currently does not provide a straightforward way to set the enctype attribute to multipart/form-data.

The form tag in Superform is currently only supporting form_action and form_method as follows:

      def around_template(&)
        form action: form_action, method: form_method do
          authenticity_token_field
          _method_field
          super
        end
      end

Would it be possible to initialize a Superform object with @enctype as for @action and @method ? And why not novalidate and target to have a full HTML form covering.

If the above is not possible, should I consider overloading the around_template method in the application_form.rb side?

Thanks a lot, very nice gem !

bradgessler commented 8 months ago

I need to dial in my GitHub alerts because I missed this, sorry!

If the above is not possible, should I consider overloading the around_template method in the application_form.rb side?

Your instinct is right to override the around_template to continue moving forward on your project. Hoping you did that!

Would it be possible to initialize a Superform object with @enctype as for @action and @method ? And why not novalidate and target to have a full HTML form covering.

I believe it would be possible. I only included those two parameters to keep the API small because I didn't have time to look at all possible HTML attributes for form.

If you have the time and desire to open a PR, I'd work with you to get improvements to the form tag merged and released.

bradgessler commented 7 months ago

0.4.2 adds support for passing attributes to the form tag, including the enctype attribute.

henri42 commented 7 months ago

Sorry for not being active on this topic, thanks a lot for the work it will be very useful !