From 0d9611021d9d502995ee2884d5dd248accdf184c Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Tue, 20 Mar 2012 15:20:25 +0100 Subject: [PATCH] Bug 6209 - Standardize on one plugin for client-side form validation Content-Type: text/plain; charset="utf-8" This patch adds the jQuery "Validation" plugin (http://docs.jquery.com/Plugins/Validation) and includes it by default in the staff client, adding one default configuration: A translatable string to be used for a default "required" message. For a simple example I have modified the library entry form to mark required fields as required (something which had not been done before). Each required field has been given a class, "required" and the HTML5 attribute "required." The former adds the hook for the plugin, the latter adds browser-based validation in recent browsers (and which will be superceded by the plugin if JavaScript is enabled). In the template the form which should be validated is initialized like so: $("#FormID").validate(); This will check for inputs classed "required" without any additional configuration. More complex forms (with specific data types, for instance) will require more inline JavaScript configuration. To test, go to Administration -> Libraries and Groups and choose "New library." Submit the form without entering a library code or name. You should be prevented from submitting the form and be shown an error message by each field. To test browser-based validation, disable JavaScript and follow the same procedure. --- .../intranet-tmpl/prog/en/css/staff-global.css | 6 ++ .../prog/en/includes/doc-head-close.inc | 2 + .../en/lib/jquery/plugins/jquery.validate.min.js | 51 ++++++++++++++++++++ .../prog/en/modules/admin/branches.tt | 23 ++++++--- 4 files changed, 74 insertions(+), 8 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/lib/jquery/plugins/jquery.validate.min.js diff --git a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css index 469f631..3e4b9e2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css +++ b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css @@ -682,6 +682,12 @@ fieldset.rows label.yesno { width : auto; } +fieldset.rows label.error { + float: none; + margin-left: 1em; + width: auto; +} + fieldset.action, div.action { clear : both; float : none; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc index bc551ac..ad3bc50 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc @@ -13,6 +13,7 @@ + [% IF ( login ) %] [% END %] @@ -46,6 +47,7 @@ [% END %] + [% INCLUDE 'header.inc' %] @@ -47,7 +54,7 @@ $(document).ready(function() { yuiToolbar(); - $.tablesorter.defaults.widgets = ['zebra']; + $.tablesorter.defaults.widgets = ['zebra']; $("#branchest").tablesorter({ sortList: [[0,0]], headers: { 3:{sorter:false},4:{sorter:false},5:{sorter:false},6:{sorter:false}} @@ -71,7 +78,7 @@ [% IF ( add ) %] [% IF ( ERROR1 ) %]
Library with that code already exists — Please enter a unique code
[% END %]

[% IF ( heading_branches_add_branch_p ) %]New library[% ELSE %]Modify library[% END %]

-
+
[% IF ( heading_branches_add_branch_p ) %] @@ -81,17 +88,17 @@ [% END %]
  1. [% IF ( heading_branches_add_branch_p ) %] - - + + Required [% ELSE %] - - + + Required [% branchcode %] [% END %]
  2. - -   + + Required
-- 1.7.5.4