katalyst / koi

Koi Gem
https://github.com/katalyst/koi
MIT License
8 stars 4 forks source link

Document field does not respect mime type override #590

Closed mattr closed 5 months ago

mattr commented 5 months ago

The custom govuk_document_field accepts mime_types as a keyword argument; however, the implementation will always use the default list:

@mime_types = MIME_TYPES || kwargs[:mime_types]

Expected behaviour

When I pass a custom mime_types array as a keyword argument, it overrides the accept attribute on the file field.

form.govuk_document_field :file, mime_types: %w[audio/* video/*]
# => <input name="model[file]" type="file" accept="audio/*,video/*" />

Alternatively, I should be able to override the accept attribute directly, as per the original file field declaration; this currently does not work with the document field, as the accept attribute is always set based on the @mime_types instance variable.

Actual behaviour

The default list of mime types is always used, and the keyword argument is added as an incorrectly formatted attribute instead.

form.govuk_document_field :file, mime_types: %w[audio/* video/*]
# => <input name="model[file]" type="file" mime_types="audio/* video/*" accept="image/png,image/gif,image/jpeg,image/webp,application/pdf,audio/*" />