mardi 7 août 2018

Wait for condition to be true, then continue function

I've been suffering for a while trying to get this to work as expected.

I have a couple of checkboxes. When I check one, the other unchecks. Every time this action happens there is a function that checks if the lenght of the checkboxes is equal to one.

The expected behavior is: that if it's equal to one, the function must continue, if not, it must wait until it is. The thing is that the checkboxes are taking way too much time to uncheck.

So, It just ignores everything and continues...

Here's the function:

  function unchecking(){
    // Here I uncheck the other checkboxes when a new one gets checked
    $('.checkbox').on('change', function() {
      $('.checkbox').not(this).prop('checked', false);  
    });

    // Then I loop
    $.each($('.checkFiltro:checkbox:checked'), function (i, checkbox){
      // I need something like this:
      if($('.checkFiltro:checkbox:checked') < 2){
        // Continue and do another thing
      } else {
        // Wait until condition is true
      }
    });
  }




Aucun commentaire:

Enregistrer un commentaire