KoolListBox issue when UseCheckBoxes is on

Jayme
HelLo,
I have set $listbox->UseCheckBoxes=true;
I am trying to use the KoolListBox::OnCheck event but it is not being triggered.
I have changed the event to OnSelect, using the same event handler and this event is being triggered.
The UnCheck event is not being triggered as well.
When I call the item->Checked() or item->Uncheck() methods the events are triggered, not through the user inetrface, though.
Best regards.
Posted Feb 10 Kool
Jayme
Hello,
I have received a new koollistbox.php file from KoolPHP Support which has been corrected and now the check / uncheck events are being fired.
I stiil have a problem. The KoolListBox do not have a selectAll nor a unselectAll methods and I have to walk through the checked list to uncheck all items in the list, but, when I call the methods to uncheck or to check the item the events are fired and the loop to change the check state for all items is interrupted.
This is the JavaScript function I am using to walk through the items of the list box:
function btLstMarkClick( sender )
{
  var _items;
  lsPtAllMarked = ! lsPtAllMarked ;
  lsPtNoneMarked = !lsPtAllMarked;
  if( lsCkPto ){
    lRunningBatchCheck = true ;
    _items = lsCkPto.get_items();
    for( i=0; i < _items.length; ++i ){
      if( lsPtAllMarked ) _items[i].check(); //marcar todos
      else _items[i].uncheck();
    }
  }
  if( lsPtAllMarked ) sender.src = btUnMarkUpImg.src;
  else sender.src = btMarkUpImg.src;
  lRunningBatchCheck = false;
}
// lRunningBatchCheck  is used to control if the check / uncheck event must be handled

Thank you very much.
Best regards.
Posted Mar 22 Kool
Jayme
Hello,
Could you please solve the problem on KoolListBox when using CheckBoxes ?
I hope you can solve the problem or I will be forced to abandon the KoolListBox control .
Please try this code:
<?php
  $KoolControlsFolder ="..\KoolPHPSuite\KoolControls";
  require $KoolControlsFolder."/KoolAjax/koolajax.php";
  require $KoolControlsFolder."/KoolListBox/koollistbox.php";
  $lsCkPto = new KoolListBox("lsCkPto");
  $lsCkPto->AllowSelect = false;
	$lsCkPto->styleFolder = "default";
  $lsCkPto->UseCheckBoxes=true;
  //$lsCkPto->width = "180px";
  $lsCkPto->Height = "195px";
  for( $i=0; $i<10; ++$i){
    $item = $lsCkPto->AddItem(new ListBoxItem('Item - '.$i));
    $item->Checked = true;
    $item->Value   = $i;
  }
  $lsCkPto->ClientEvents["OnCheck"  ] = "checkAllChecked";
  $lsCkPto->ClientEvents["OnUnCheck"] = "checkAllChecked";
  $lsCkPto->Init();
?>
<!DOCTYPE HTML>
<html>
<head>
  <title>Solve this please!</title>
  <META name="purpose" content="Check / Unchek items, Check All Items, Uncheck All Items, Get Which are Checked or not">
  <META name="generator" content="Rapid PPHP 2015">
  <script type="text/javascript" language="JavaScript">
    var lsPtAllMarked      = true;
    var lRunningBatchCheck = false;
    function checkAllChecked()
    {
      var _items;
      var numItems;
      var btn;
      if(lRunningBatchCheck) return;
      btn = document.getElementById("btListMark");
      lsPtAllMarked = true;
      if( lsCkPto ){
        _items   = lsCkPto.get_items();
        numItems = _items.length;
        for( i=0; i<numItems; ++i ) {
          if( ! _items[i].get_checked() ) {
            lsPtAllMarked = false;
            break;
          }
        }
      }
      if( lsPtAllMarked ) btn.value = "Uncheck All";
      else btn.value = "Check All";
    }
    //----------------------------------------------------------------------
    function btLstMarkClick( sender )
    {
      var _items;
      lsPtAllMarked = ! lsPtAllMarked ;
      if( lsCkPto ){
        lRunningBatchCheck = true ;
        _items = lsCkPto.get_items();
        for( i=0; i < _items.length; ++i ){
          if( lsPtAllMarked ) _items[i].check(); //check all
          else _items[i].uncheck();
        }
      }
      if( lsPtAllMarked ) sender.value = "Uncheck All";
      else sender.value = "Check All";
      lRunningBatchCheck = false;
    }
    //----------------------------------------------------------------------
    function showChecked()
    {
      var _items;
      var sChecked = "";
      var nChecked = 0;
      _items = lsCkPto.get_items();
      for( i=0; i < _items.length; ++i ){
        if( _items[i].get_checked() )  {
          sChecked += _items[i].get_text();
          ++nChecked;
        }
      }
      if( sChecked.length > 0 ) {
        alert( "There are "+nChecked+ " checked!\n"+sChecked + " are checked!") ;
      }
      else alert("None checked!");
    }
    //----------------------------------------------------------------------
  </script>
</head>
<body>
  <div>
    <?php echo $lsCkPto->Render(); ?>
    <p><input id="btListMark" name="btListMark" type="button" value="Uncheck All" style="width:100px; "onclick="btLstMarkClick(this);">
       <input name="btShowChecked" type="button" value="Show Checked" style="width:100px;" onclick="showChecked();"></p>
  </div>
</body>
</html>

You will see that the answer which is got when you press " Show Checked" do not correspond to reality.
Best regards.
Jayme Jeffman
Posted Apr 11 Kool
David
Hi Jayme,
Thanks for your feedback! We have debugged your code and found the error lied in this line in the showChecked() function:
for( i=0; i < _items.length; ++i )

Basically here i is a global variable in global scope. Unfortunately, in our get_data() function there's also a same mistake using global i in a for loop which conflicts with your variable. We have fixed this bug for the next release of KoolPHP. Meanwhile, you could make a change for your code to make i local and safe:
for(var i=0; i < _items.length; ++i )

Please let us know if it works for you. Thanks!
Posted Apr 12 Kool -
Anthony Amolochitis
Great catch!
Posted Apr 12 Kool