Bug 7628 - Required format is not enforced for Patron Categories
authorMarc Veron <veron@veron.ch>
Wed, 18 Jul 2012 05:57:36 +0000 (07:57 +0200)
committerPaul Poulain <paul.poulain@biblibre.com>
Fri, 3 Aug 2012 13:01:01 +0000 (15:01 +0200)
Enforces category code with allowed characters only.

Test plan:

- Before applying patch, create a category code like Test+

- Try to delete category with this code -> does not work

- Apply patch

- Try to create category with code containg other characters than letters, numbers, - and _

- Result: You are not allowed to do so, appropriate message pops up

Signed-off-by: David Cook <dcook@prosentient.com.au>
koha-tmpl/intranet-tmpl/prog/en/modules/admin/categorie.tt

index e0be34b..8fd512c 100644 (file)
            var ok=0;
                var _alertString=_("Form not submitted because of the following problem(s)");
                _alertString +="\n-------------------------------------------------------------------\n\n";
-               if (ff.categorycode.value.length==0) {
-                   ok=1;
-                       _alertString += _("- categorycode missing") + "\n";
-               }
+                ff.categorycode.value = ff.categorycode.value.trim();
+                if (ff.categorycode.value.length==0) {
+                   ok=1;
+                   _alertString += _("- categorycode missing") + "\n";
+                }
+                else{
+                   var patt=/^[a-zA-Z0-9\-_]+$/g;
+                   if ( !patt.test(ff.categorycode.value) ) {
+                      ok=1;
+                      _alertString += _("- category code can only contain the following characters: letters, numbers, - and _") + "\n";
+                   }
+                }
                if (!(ff.category_type.value)){
                    ok=1;
                    _alertString += _("- category type missing") + "\n";