From bbcf03cd962bfab916a8f17f3ba15d5dad7077d8 Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Thu, 14 Sep 2023 20:18:01 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Remove=20PDF.js=20related=20fiel?= =?UTF-8?q?ds=20from=20form?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `show_pdf_viewer` and `show_pdf_download_button` fields were showing up on the form so this commit will remove them. --- app/forms/hyrax/pdf_form_behavior.rb | 7 +++++ .../records/edit_fields/_default.html.erb | 31 ++++++++++--------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/app/forms/hyrax/pdf_form_behavior.rb b/app/forms/hyrax/pdf_form_behavior.rb index f95c6de70..cd909a56a 100644 --- a/app/forms/hyrax/pdf_form_behavior.rb +++ b/app/forms/hyrax/pdf_form_behavior.rb @@ -5,7 +5,14 @@ module PdfFormBehavior extend ActiveSupport::Concern included do + class_attribute :hidden_terms + self.terms += %i[show_pdf_viewer show_pdf_download_button] + self.hidden_terms = %i[show_pdf_viewer show_pdf_download_button] + end + + def hidden?(key) + hidden_terms.include? key.to_sym end end end diff --git a/app/views/records/edit_fields/_default.html.erb b/app/views/records/edit_fields/_default.html.erb index aa83a89c8..0e484100f 100644 --- a/app/views/records/edit_fields/_default.html.erb +++ b/app/views/records/edit_fields/_default.html.erb @@ -1,18 +1,19 @@ <%# OVERRIDE: HydraEditor 5.0.5 support dynamic labels and hints for custom worktypes %> <%# Avoid NoMethod error when rendering partial in Collection or batch edit form %> +<%# Hide unwanted fields from the form %> +<% return if f.object.try(:hidden?, key) %> - <% record = f.object.model %> - <% if f.object.multiple? key %> - <%= f.input key, - as: :multi_value, - label: label_for(term: key, record_class: record.class), - hint: hint_for(term: key, record_class: record.class), - input_html: { class: 'form-control' }, - required: f.object.required?(key) %> - <% else %> - <%= f.input key, - label: label_for(term: key, record_class: record.class), - hint: hint_for(term: key, record_class: record.class), - required: f.object.required?(key) %> - <% end %> - +<% record = f.object.model %> +<% if f.object.multiple? key %> + <%= f.input key, + as: :multi_value, + label: label_for(term: key, record_class: record.class), + hint: hint_for(term: key, record_class: record.class), + input_html: { class: 'form-control' }, + required: f.object.required?(key) %> +<% else %> + <%= f.input key, + label: label_for(term: key, record_class: record.class), + hint: hint_for(term: key, record_class: record.class), + required: f.object.required?(key) %> +<% end %>