Skip to content

Commit

Permalink
editor: prevent the enter key to submit the form
Browse files Browse the repository at this point in the history
* Prevents the enter key to submit the form in some fields that may be
  filled though a scanning device.
* Closes rero#1421.

Co-Authored-by: Johnny Mariéthoz <johnny.mariethoz@rero.ch>
  • Loading branch information
jma and jma committed Mar 16, 2021
1 parent 8e2f9f8 commit 30d9085
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@
"minLength": 1,
"form": {
"templateOptions": {
"itemCssClass": "col-lg-6"
"itemCssClass": "col-lg-6",
"doNotSubmitOnEnter": true
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,12 @@
},
"identifier": {
"type": "string",
"title": "Identifier"
"title": "Identifier",
"form": {
"templateOptions": {
"doNotSubmitOnEnter": true
}
}
},
"source": {
"type": "object",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h4 class="alert-heading">{{ _('Caution!') }}</h4>
<p class="mb-0">{{ _('A well detailed request is more likely to be satisfied') }}</p>
</div>

<form action="{{ url_for('ill_requests.ill_request_form') }}" method="POST" class="form" role="form" novalidate>
<form id="ill-public-form" action="{{ url_for('ill_requests.ill_request_form') }}" method="POST" class="form" role="form" novalidate>
{{ form.hidden_tag() }}
{%- if form.csrf_token and form.csrf_token.errors %}
<div class="alert alert-danger" role="alert">
Expand Down Expand Up @@ -62,8 +62,28 @@ <h3>{{ _('Request information') }}</h3>
</section>
<div class="row pt-3">
<div class="col text-right">
<input type="submit" id="submit" class="btn btn-primary" value="{{ _('Create request') }}"/>
<input type="submit" id="submit" class="btn btn-primary" value="{{ _('Submit') }}"/>
</div>
</div>
</form>

<div id="ill-modal-confirmation" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">{{ _('Confirmation') }}</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p>{{ _('Costs may apply. By confirming, you agree to the interlibrary loan conditions of the pick-up library.') }}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-danger" data-dismiss="modal">{{ _('Cancel') }}</button>
<button id="ill-modal-confirmation-btn" type="button" class="btn btn-primary">{{ _('Confirm') }}</button>
</div>
</div>
</div>
</div>
{%- endblock body %}
3 changes: 2 additions & 1 deletion rero_ils/modules/items/jsonschemas/items/item-v0.0.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"form": {
"focus": true,
"templateOptions": {
"labelClasses": "col-2 text-right"
"labelClasses": "col-2 text-right",
"doNotSubmitOnEnter": true
},
"navigation": {
"essential": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@
"type": "string",
"minLength": 6,
"form": {
"templateOptions": {
"doNotSubmitOnEnter": true
},
"validation": {
"validators": {
"valueAlreadyExists": {
Expand Down
36 changes: 36 additions & 0 deletions rero_ils/theme/assets/js/reroils/ills_request.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
RERO ILS
Copyright (C) 2019 RERO
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, version 3 of the License.
This program 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import $ from 'jquery';

// show a confirmation modal dialog on form submission
$("#submit").on("click", function(event){
if($(this).data('confirmed') !== true) {
$("#ill-modal-confirmation").modal('show');
event.preventDefault();
}
});

// close the dialog, confirmed is true and trigger the submit click button
$("#ill-modal-confirmation-btn").on("click", function(event){
$( "#submit" ).data('confirmed', true);
$("#ill-modal-confirmation").modal('hide');
// form submit does not works
$("#submit").trigger('click');
});
4 changes: 3 additions & 1 deletion rero_ils/theme/assets/js/reroils/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import 'bootstrap';
import './tooltip';
import './toast';
import './login';
import './toggle';
import './ills_request';


0 comments on commit 30d9085

Please sign in to comment.