%= bootstrap_form_for document, url: spotlight.polymorphic_path([current_exhibit, document]), html: {:'data-form-observer' => true, multipart: true} do |f| %>
<%= f.fields_for :sidecar, document.sidecar(current_exhibit) do |c| %>
<%= c.check_box :public %>
<% end %>
<%= f.fields_for :uploaded_resource do |r| %>
<%= r.url_field :url, type: "file", help: t('.url-field.help', extensions: Spotlight::Engine.config.allowed_upload_extensions.join(' ')), label: "File" %>
<% end if document.uploaded_resource? %>
<%= f.fields_for :sidecar, document.sidecar(current_exhibit) do |c| %>
<%= c.fields_for :data do |d| %>
<% if document.uploaded_resource? %>
<%= d.fields_for :configured_fields do |e| %>
<% Spotlight::Resources::Upload.fields(current_exhibit).each do |config| %>
<%= e.send((config.form_field_type || :text_field), config.field_name, value: (document.sidecar(current_exhibit).data["configured_fields"] || {})[config.field_name.to_s], label: uploaded_field_label(config)) %>
<% end %>
<% end %>
<% end %>
<%# Using `includes(:exhibit)` to ensure all fields are using the same exhibit object to take advantage of memoization %>
<% current_exhibit.custom_fields.includes(:exhibit).each do |field| %>
<% end %>
<% end %>
<% end %>
<% if can? :tag, current_exhibit %>
<%= f.text_field :exhibit_tag_list, value: f.object.tags_from(current_exhibit).to_s, 'data-autocomplete_url' => exhibit_tags_path(current_exhibit, format: 'json') %>
<% end %>
<% end %>