<% required_docs = local_assigns[:required_docs] || [] %> <% title_normalized = f.object.title.to_s.strip.downcase %> <% is_mandatory = f.object.mandatory || required_docs.any? { |t| t.to_s.strip.downcase == title_normalized } %> <% has_file = f.object.file.attached? %>
<%= f.label :title, class: "form-label" %> <%= f.text_field :title, class: "form-control", placeholder: "Document Title", readonly: is_mandatory %> <% if is_mandatory %> Mandatory document <% end %>
<%= f.label :file, class: "form-label" %> <% if has_file %>
📎 <%= f.object.file.filename %> — <%= link_to "Preview", url_for(f.object.file), target: "_blank", class: "text-decoration-none ms-1" %>
<% if f.object.file.image? %>
<%= image_tag f.object.file.variant(resize_to_limit: [220, 140]), class: "img-thumbnail shadow-sm" %>
<% end %> <% end %> <%= f.file_field :file, class: "form-control" %> <% if is_mandatory %> Upload is required <% end %>
<% unless is_mandatory %> <% end %> <%= f.hidden_field :_destroy %>