From 97d4689772442857b845a4c0fd8a8c0628ca2dfc Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Fri, 12 Oct 2018 15:46:43 +0000 Subject: [PATCH] Bug 20689: (follow-up) Make it possible to add capital letter subfields to item search fields This patch adds some custom validation to the MARC tag and subfield fields so that they are limited to alphanumeric characters. Both templates (the main view and the edit view) have been modified so that item_search_fields.js can be included in both. To test, apply the patch and test the form by entering a variety of different character combinations. The "MARC field" and "MARC subfield" inputs should only accept alphanumeric entries. Test both "new" and "edit" operations. Test other operations like delete and cancel. Signed-off-by: Mark Tompsett Signed-off-by: Jose-Mario Signed-off-by: Chris Cormack Signed-off-by: Katrin Fischer Signed-off-by: Martin Renvoize Signed-off-by: Fridolin Somers --- .../admin-items-search-field-form.inc | 8 ++--- .../en/modules/admin/items_search_field.tt | 3 +- .../en/modules/admin/items_search_fields.tt | 4 +-- .../prog/js/item_search_fields.js | 36 +++++++++++++++++-- 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-items-search-field-form.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/admin-items-search-field-form.inc index 7232766b1a..b95e263d91 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-items-search-field-form.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/admin-items-search-field-form.inc @@ -23,18 +23,18 @@
  • [% IF field && field.tagfield == tagfield %] - + [% ELSE %] - + [% END %] Required
  • [% IF field && field.tagsubfield == tagsubfield %] - + [% ELSE %] - + [% END %]
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/items_search_field.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/items_search_field.tt index ddad79786e..a5a0e009fe 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/items_search_field.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/items_search_field.tt @@ -46,7 +46,7 @@

    Item search field: [% field.label | html %]

    -
    +
    Edit field [% INCLUDE 'admin-items-search-field-form.inc' field=field %] @@ -72,6 +72,7 @@ [% MACRO jsinclude BLOCK %] [% Asset.js("js/admin-menu.js") | $raw %] + [% Asset.js("js/item_search_fields.js") | $raw %] [% END %] [% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/items_search_fields.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/items_search_fields.tt index ab6139dcfb..c2168f1001 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/items_search_fields.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/items_search_fields.tt @@ -102,7 +102,7 @@ [% END %] - +
    Add a new field [% INCLUDE 'admin-items-search-field-form.inc' field=undef %] @@ -110,7 +110,7 @@
    - Cancel + Cancel
    diff --git a/koha-tmpl/intranet-tmpl/prog/js/item_search_fields.js b/koha-tmpl/intranet-tmpl/prog/js/item_search_fields.js index 6080798e75..33d6c25058 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/item_search_fields.js +++ b/koha-tmpl/intranet-tmpl/prog/js/item_search_fields.js @@ -1,4 +1,9 @@ -/* global __ */ +/* global _ MSG_ITEM_SEARCH_DELETE_CONFIRM */ + +jQuery.validator.addMethod("marcfield", function(value, element) { + return this.optional(element) || /^[0-9a-zA-Z]+$/.test(value); +}, _("Please enter letters or numbers") ); + $(document).ready(function(){ $("#add_field_form").hide(); $("#new_search_field").on("click",function(e){ @@ -7,7 +12,7 @@ $(document).ready(function(){ $(".dialog").hide(); $("#search_fields_list,#toolbar").hide(); }); - $(".cancel").on("click",function(e){ + $(".hide_form").on("click",function(e){ e.preventDefault(); $("#add_field_form").hide(); $(".dialog").show(); @@ -22,4 +27,31 @@ $(document).ready(function(){ return false; } }); + + $("#add_field_form").validate({ + rules: { + label: "required", + tagfield: { + required: true, + marcfield: true + }, + tagsubfield: { + marcfield: true + } + } + }); + + $("#edit_search_fields").validate({ + rules: { + label: "required", + tagfield: { + required: true, + marcfield: true + }, + tagsubfield: { + marcfield: true + } + } + }); + }); -- 2.39.5