Bug 11785 - Use validation plugin when uploading local cover images

When uploading local cover images the form should not be submitted if
no file has been selected. The existing form validation script doesn't
work. This patch adds HTML5 validation attributes and use of Koha's
built-in form validation plugin.

To test, apply the patch and go to Tools -> Upload local cover image.
Try to submit the form without selecting a file to upload. You should be
prevented from doing so. Choose a file and confirm that the upload
completes 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>
(cherry picked from commit 7faff33c8b)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
(cherry picked from commit fc50362c23)
This commit is contained in:
Owen Leonard 2014-02-18 12:13:39 -05:00 committed by Kyle M Hall
parent 4b0feb1a0f
commit c154bc548b
1 changed files with 9 additions and 12 deletions

View File

@ -17,16 +17,12 @@ $(document).ready(function(){
$("#image").click(function(){
$("#bibnum").show();
});
$("#uploadfile").validate({
submitHandler: function(form) {
ajaxFileUpload();
}
});
});
function CheckForm(f) {
if ($("#fileToUpload").value == '') {
alert(_("Please upload a file first."));
} else {
return submitBackgroundJob(f);
}
return false;
}
//]]>
</script>
</head>
@ -72,11 +68,12 @@ function CheckForm(f) {
<ol>
<li>
<div id="fileuploadform">
<label for="fileToUpload">Select the file to upload: </label>
<input type="file" id="fileToUpload" name="fileToUpload" />
<label for="fileToUpload" class="required">Select the file to upload: </label>
<input type="file" id="fileToUpload" name="fileToUpload" required="required" class="required" />
<span class="required">Required</span>
</div> </li>
</ol>
<fieldset class="action"><button class="submit" onclick="return ajaxFileUpload();">Upload file</button></fieldset>
<fieldset class="action"><button class="submit">Upload file</button></fieldset>
</fieldset>
<div id="uploadpanel"><div id="fileuploadstatus">Upload progress: <div id="fileuploadprogress"></div> <span id="fileuploadpercent">0</span>%</div>