Bug 11788 - Use validation plugin when creating new course

The page for adding a new course includes some custom form
validation JavaScript which can be removed in favor of HTML5 validation
attributes and Koha's built-in validation plugin. This patch does so.

To test, apply the patch and go to Course reserves -> New course. Try
submitting the form without entering a department, course number,
and/or course name. This should trigger validation warnings.

Submission of the form with valid data should work correctly. Editing an
existing course should also work correctly.

Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
This commit is contained in:
Owen Leonard 2014-02-18 15:26:30 -05:00 committed by Galen Charlton
parent 03675fd553
commit 4e9b5110d9

View file

@ -4,38 +4,6 @@
[% IF ( departments ) %]
<script type="text/javascript">
//<![CDATA[
function Check(f) {
var _alertString = "";
if( ! $("#department").val() ) {
_alertString += _("- You must choose a department") + "\n";
}
if( ! $("#course_number").val() ) {
_alertString += _("- You must choose a course number") + "\n";
}
if( ! $("#course_name").val() ) {
_alertString += _("- You must add a course name") + "\n";
}
if ( _alertString.length ) {
var alertHeader;
alertHeader = _("Form not submitted because of the following problem(s)");
alertHeader += "\n------------------------------------------------------------------------------------\n\n";
alert( alertHeader + _alertString );
} else {
f.submit();
}
}
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
$(document).ready(function(){
@ -100,14 +68,14 @@
<div id="doc" class="yui-t7">
<div id="bd">
<form method="post" action="/cgi-bin/koha/course_reserves/mod_course.pl">
<form method="post" action="/cgi-bin/koha/course_reserves/mod_course.pl" class="validated">
[% IF course_id %]<input type="hidden" name="course_id" value="[% course_id %]" />[% END %]
<fieldset class="rows">
<legend>[% IF course_id %]Edit course[% ELSE %]Create course[% END %]</legend>
<ol>
<li>
<label class="required" for="department">Department:</label>
<select id="department" name="department">
<select id="department" name="department" required="required" class="required">
<option value="">Select a department</option>
[% FOREACH d IN departments %]
@ -118,11 +86,13 @@
[% END %]
[% END %]
</select>
<span class="required">Required</span>
</li>
<li>
<label class="required" for="course_number">Course number:</label>
<input id="course_number" name="course_number" type="text" value="[% course_number %]" />
<input id="course_number" name="course_number" type="text" value="[% course_number %]" required="required" class="required" />
<span class="required">Required</span>
</li>
<li>
@ -132,7 +102,8 @@
<li>
<label class="required" for="course_name">Course name:</label>
<input id="course_name" name="course_name" type="text" value="[% course_name %]" />
<input id="course_name" name="course_name" type="text" value="[% course_name %]" required="required" class="required" />
<span class="required">Required</span>
</li>
<li>
@ -195,7 +166,7 @@
</fieldset>
<fieldset class="action">
<input type="submit" onclick="Check(this.form); return false;" value="Save" class="submit" />
<input type="submit" value="Save" class="submit" />
<a href="/cgi-bin/koha/course_reserves/course-reserves.pl" class="cancel">Cancel</a>
</fieldset>