Bug 14070: Prevent to save a letter if an error occurred
authorJonathan Druart <jonathan.druart@koha-community.org>
Fri, 22 May 2015 09:58:18 +0000 (11:58 +0200)
committerTomas Cohen Arazi <tomascohen@theke.io>
Wed, 17 Jun 2015 12:55:40 +0000 (09:55 -0300)
On saving a letter, if the title or the content of a template is not
defined, a JS alert is raised. But the form is submitted anyway.
This patch prevent the form to be submitted.

Test plan:
- Create or edit a letter
- Fill the title for a template, not the content
- Save
- Confirm you get the alert and that the form is not submitted

http://bugs.koha-community.org/show_bug.cgi?id=14070

Signed-off-by: Indranil Das Gupta <indradg@gmail.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt

index 3106498..06bf585 100644 (file)
@@ -30,6 +30,7 @@ $(document).ready(function() {
     $("#submit_form").click( function(event) {
         event.preventDefault();
         var at_least_one_exists = 0;
+        var are_valid = 1;
         $("fieldset.mtt").each( function(){
             var title = $(this).find('input[name="title"]').val();
             var content = $(this).find('textarea[name="content"]').val();
@@ -41,8 +42,8 @@ $(document).ready(function() {
                 var msg = _("Please specify title and content for %s");
                 msg = msg.replace( "%s", mtt );
                 at_least_one_exists = 1;
-                alert(msg)
-                return false;
+                alert(msg);
+                return are_valid = false;
             } else if ( title.length > 0 && content.length > 0 ) {
                 at_least_one_exists = 1;
             }
@@ -51,6 +52,9 @@ $(document).ready(function() {
             alert( _("Please fill at least one template.") );
             return false;
         }
+        if ( ! are_valid ) {
+            return false;
+        }
 
         // Test if code already exists in DB
         var new_lettercode = $("#code").val();