<% # formstrap/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 "formstrap/file", form: form, attribute: :file %#> # <% end %#> file = Formstrap::FileView.new(local_assigns) %> <%= render "formstrap/wrapper", file.wrapper_options do %> <%= render "formstrap/label", file.label_options if file.prepend_label? %>
> <%= render "formstrap/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) %>
" 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 "formstrap/shared/thumbnail", file: attachment %> <% if file.destroy %>
<%= bootstrap_icon("x") %>
<% end %>
<% end %> <% if file.dropzone %>
" data-file-preview-target="placeholder" style="height: 100px;"> <%= t(".placeholder", count: file.number_of_files) %>
<% else %>
" title="<%= t(".not_found") %>" data-file-preview-target="placeholder"> <%= render "formstrap/shared/thumbnail", icon: "plus" %>
<% end %>
<% end %> <%= form.file_field(attribute, file.input_options) %> <% end %>
<%= render "formstrap/validation", file.validation_options if file.validate? %> <%= render "formstrap/hint", file.hint_options if file.hint? %> <%= render "formstrap/label", file.label_options if file.append_label? %> <% end %>