From 3bfc32a6786d4e5e66278820115f9ed7c922db15 Mon Sep 17 00:00:00 2001 From: j3nsch Date: Wed, 4 Dec 2024 12:49:43 +0100 Subject: [PATCH] #1258 Limit ENTER handling to forms publish and metadata --- .../admin/controllers/DocumentController.php | 1 + .../publish/controllers/FormController.php | 1 + public/layouts/opus4/js/form-enter.js | 41 +++++++++++++++++++ public/layouts/opus4/js/submit.js | 9 ---- 4 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 public/layouts/opus4/js/form-enter.js diff --git a/modules/admin/controllers/DocumentController.php b/modules/admin/controllers/DocumentController.php index 606b4de25..614976eba 100644 --- a/modules/admin/controllers/DocumentController.php +++ b/modules/admin/controllers/DocumentController.php @@ -51,6 +51,7 @@ public function init() { parent::init(); $this->documentsHelper = $this->_helper->getHelper('Documents'); + $this->view->headScript()->prependFile($this->view->layoutPath() . '/js/form-enter.js'); } /** diff --git a/modules/publish/controllers/FormController.php b/modules/publish/controllers/FormController.php index 7ae50b7b2..a1467fc76 100644 --- a/modules/publish/controllers/FormController.php +++ b/modules/publish/controllers/FormController.php @@ -53,6 +53,7 @@ public function init() { $this->session = new Zend_Session_Namespace('Publish'); parent::init(); + $this->view->headScript()->prependFile($this->view->layoutPath() . '/js/form-enter.js'); } /** diff --git a/public/layouts/opus4/js/form-enter.js b/public/layouts/opus4/js/form-enter.js new file mode 100644 index 000000000..6b48659bd --- /dev/null +++ b/public/layouts/opus4/js/form-enter.js @@ -0,0 +1,41 @@ +/** + * This file is part of OPUS. The software OPUS has been originally developed + * at the University of Stuttgart with funding from the German Research Net, + * the Federal Department of Higher Education and Research and the Ministry + * of Science, Research and the Arts of the State of Baden-Wuerttemberg. + * + * OPUS 4 is a complete rewrite of the original OPUS software and was developed + * by the Stuttgart University Library, the Library Service Center + * Baden-Wuerttemberg, the Cooperative Library Network Berlin-Brandenburg, + * the Saarland University and State Library, the Saxon State Library - + * Dresden State and University Library, the Bielefeld University Library and + * the University Library of Hamburg University of Technology with funding from + * the German Research Foundation and the European Regional Development Fund. + * + * LICENCE + * OPUS is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the Licence, or any later version. + * OPUS is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. You should have received a copy of the GNU General Public License + * along with OPUS; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * @copyright Copyright (c) 2024, OPUS 4 development team + * @license http://www.gnu.org/licenses/gpl.html General Public License + */ + +$(function () { + + // Prevent submission of form when Enter/Return is pressed in a simple text input + $('form').on('keydown', e => { + if (e.key === 'Enter') { + if ($(e.target).is("input[type='text']")) { + e.preventDefault(); + } + } + }); + +}); diff --git a/public/layouts/opus4/js/submit.js b/public/layouts/opus4/js/submit.js index 73082554c..fc360bbce 100644 --- a/public/layouts/opus4/js/submit.js +++ b/public/layouts/opus4/js/submit.js @@ -36,13 +36,4 @@ $(function () { }); }); - // Prevent submission of form when Enter/Return is pressed in a simple text input - $('form').on('keydown', e => { - if (e.key === 'Enter') { - if ($(e.target).is("input[type='text']")) { - e.preventDefault(); - } - } - }); - });