Bug 16949: Simplify the checkbox checked condition
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 13 Sep 2016 08:06:12 +0000 (09:06 +0100)
committerKyle M Hall <kyle@bywatersolutions.com>
Tue, 13 Sep 2016 17:24:38 +0000 (17:24 +0000)
It's easier to use jQuery selector to know if checkboxes are checked.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_delete_records.tt

index ceb5bd4..7962a9f 100644 (file)
@@ -61,21 +61,9 @@ $(document).ready(function() {
     "bPaginate": false
   }));
 
-  function Checkbox(){
-    var form = document.getElementById('selectrecords');
-    var inputs = form.getElementsByTagName('input');
-    var checked = false;
-    for (var i=0; i<inputs.length; i++) {
-      if (inputs[i].type == 'checkbox' && inputs[i].name == 'record_id') {
-        checked = inputs[i].checked;
-        if (checked) return true;
-      }
-    }
-    return false;
-  }
-
   $("#selectrecords").on("submit",function(){
-    if (Checkbox() == false){
+    var nb_checked = $("#selectrecords").find("input[type='checkbox'][name='record_id']:checked").size();
+    if (nb_checked == 0){
       alert(_("No records have been selected."));
       return false;
     }