From 9ad083e922cf96e7f04fa72b4d71a81bc4edd381 Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Wed, 13 Mar 2024 12:56:32 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20banner=20alt=20text=20requ?= =?UTF-8?q?ire?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The banner crop javascript was doing a `e.preventDefault();` which then allowed the form being submitted without the alt text which is a required field. This commit will add a check to see if all the required fields are filled in and if not then the function should not execute and therefore not preventDefault. Ref: - https://github.com/scientist-softserv/palni-palci/issues/948 --- .../admin/appearances/_banner_image_form.html.erb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/views/hyrax/admin/appearances/_banner_image_form.html.erb b/app/views/hyrax/admin/appearances/_banner_image_form.html.erb index 867d2f540..9c424ba22 100644 --- a/app/views/hyrax/admin/appearances/_banner_image_form.html.erb +++ b/app/views/hyrax/admin/appearances/_banner_image_form.html.erb @@ -67,6 +67,17 @@ }); document.querySelector('.banner-submit').addEventListener('click', function(e) { + // Get all required fields + var requiredFields = document.querySelectorAll('input[required],textarea[required],select[required]'); + + // Check if all required fields are filled + for (var i = 0; i < requiredFields.length; i++) { + if (!requiredFields[i].value) { + // return early if not all required fields have been filled out + return; + } + } + e.preventDefault(); // Show the spinner