From c4bf3939a2c3cb7d0441a757d17983bdc2917dfe Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Mon, 13 May 2013 12:16:03 -0400 Subject: [PATCH] Bug 10237 - Enforce authorized value character limitations Content-Type: text/plain; charset="utf-8" An authorized value should not have spaces or special characters other than underscores and hyphens in it, but this limitation is not enforced. This patch adds client-side validation blocking entries which contain anything other than numbers, letters, underscores, or dashes. Changes include: - The addition of a custom alphanumeric validation scheme which can be used anywhere in Koha. - The addition of a new translatable warning message which appears when the alphanumeric validation scheme is violated. - The addition of rules to the authorized_values.tt template to enable the new alphanumeric validation scheme. To test, apply the patch and clear your browser cache. With an existing category of authorized values (like ccode): - Click to add new authorized value - Try to enter invalid data in the "authorized value" form field. You should see a warning. - Try to submit a form with the invalid data. You should be prevented from doing to. - Correct the invalid data to conform to the validation rules. Warnings should disappear. - Submit the form. It should submit correctly. With a new category: - Click to create a new category. - Try to enter invalid data in the "category" and "authorized value" form fields. You should see warnings. - Try to submit a form with the invalid data. You should be prevented from doing to. - Correct the invalid data to conform to the validation rules. Warnings should disappear. - Submit the form. It should submit correctly. --- .../prog/en/includes/validator-strings.inc | 1 + koha-tmpl/intranet-tmpl/prog/en/js/staff-global.js | 4 +++ .../prog/en/modules/admin/authorised_values.tt | 26 +++++++++++++++----- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/validator-strings.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/validator-strings.inc index 2ca4430..5259ba7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/validator-strings.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/validator-strings.inc @@ -11,6 +11,7 @@ $(document).ready(function(){ number: _("Please enter a valid number."), digits: _("Please enter only digits."), equalTo: _("Please enter the same value again."), + alphanumeric: _("Please use only letters, numbers, underscores, or dashes."), maxlength: $.validator.format(_("Please enter no more than {0} characters.")), minlength: $.validator.format(_("Please enter at least {0} characters.")), rangelength: $.validator.format(_("Please enter a value between {0} and {1} characters long.")), diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/staff-global.js b/koha-tmpl/intranet-tmpl/prog/en/js/staff-global.js index 2bf385f..25c6d59 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/js/staff-global.js +++ b/koha-tmpl/intranet-tmpl/prog/en/js/staff-global.js @@ -53,3 +53,7 @@ function openWindow(link,name,width,height) { height = (typeof height == "undefined")?'400':height; var newin=window.open(link,name,'width='+width+',height='+height+',resizable=yes,toolbar=false,scrollbars=yes,top'); } + +jQuery.validator.addMethod("alphanumeric", function(value, element) { + return this.optional(element) || /^[a-z0-9_\-]+$/i.test(value); +}); \ No newline at end of file diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt index 5ba3072..1bcf228 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt @@ -27,6 +27,20 @@ $("#branches option:first").attr("selected", "selected"); } $('#icons').tabs(); + + $("#authval_form").validate({ + rules: { + "category": { + required: true, + alphanumeric: true + }, + "authorised_value": { + required: true, + alphanumeric: true + } + } + }); + }); //]]> @@ -75,24 +89,24 @@ $(document).ready(function() { [% IF ( action_modify ) %]
NOTE: If you change an authorized value, existing records using it won't be updated.
[% END %] -
+
  1. - [% IF ( action_add_category ) %] - + [% IF ( action_add_category ) %] + [% ELSE %]Category [% category %] [% END %]
  2. - + [% IF ( action_modify ) %][% END %] [% IF ( action_add_category ) %] - + [% ELSE %] - + [% END %]
  3. -- 1.7.9.5