<% # headmin/forms/file # # ==== Required parameters # * +attribute+ - Name of the attribute of the form model # * +form+ - Form object # # ==== Optional parameters # * +append+ - Display as input group with text on the right-hand side # * +destroy+ - Adds delete buttons to the preview thumbnails # * +dropzone+ - Add drag&drop interface. This setting automatically enables previews # * +hint+ - Informative text to assist with data input. HTML markup is allowed. # * +multiple+ - Add drag&drop interface. This setting automatically enables previews # * +preview+ - Show file previews after selection and after upload # * +label+ - Text to display inside label tag. Defaults to the attribute name. Set to false if you don"t want to show a label. # * +prepend+ - Display as input group with text on the left-hand side # * +wrapper+ - Hash with all options for the surrounding html tag # # ==== References # https://headmin.dev/docs/forms/file # https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file # https://apidock.com/rails/ActionView/Helpers/FormHelper/file_field # # ==== Examples # Basic version # <%= form_with do |form| %#> # <%= render 'headmin/forms/file', form: form, attribute: :file %#> # <% end %#> file = Headmin::Form::FileView.new(local_assigns) %> <%= render 'headmin/forms/wrapper', file.wrapper_options do %> <%= render 'headmin/forms/label', file.label_options if file.prepend_label? %>
> <%= render 'headmin/forms/input_group', file.input_group_options do %> <% if file.preview %>
<%= form.fields_for(file.nested_attribute) do |ff| %> <% attachment = ff.object next unless attachment filename = attachment.blob.filename.to_s size = number_to_human_size(attachment.blob.byte_size) src = attachment.image? ? url_for(attachment.variant(resize_to_fill: [file.thumbnail_width, file.thumbnail_height])) : url_for(attachment) %>
" data-file-preview-target="thumbnail"> <%= ff.hidden_field(:id, disabled: !file.destroy) %> <%= ff.hidden_field(:_destroy, data: {'file-preview-target': 'thumbnailDestroy'}, disabled: !file.destroy) %> <%= render 'headmin/thumbnail', src: src, width: file.thumbnail_width, height: file.thumbnail_height %> <% if file.destroy %>
<%= bootstrap_icon('x') %>
<% end %>
<% end %> <% if file.dropzone %>
<%= t('headmin.forms.file.placeholder', count: file.number_of_files) %>
<% else %>
<%= render 'headmin/thumbnail', width: file.thumbnail_width, height: file.thumbnail_height, icon: "plus" %>
<% end %>
<% end %> <%= form.file_field(attribute, file.input_options) %> <% end %>
<%= render 'headmin/forms/validation', file.validation_options if file.validate? %> <%= render 'headmin/forms/hint', file.hint_options if file.hint? %> <%= render 'headmin/forms/label', file.label_options if file.append_label? %> <% end %>