lundi 25 octobre 2021

CheckboxTree keeps closing and not staying open

I set up the CheckboxTree plugin. One of the errors I can't find is that CheckboxTree keeps closing and not staying open. CheckboxTree should only close when I press the minus icon. I think it is due to this part of the jQuery code:

$('input[type="checkbox"]').change(function(e) {
  var checked = $(this).prop("checked"),
    container = $(this).parent(),
    siblings = container.siblings();

  container.find('input[type="checkbox"]').prop({
    indeterminate: false,
    checked: checked
  });

  function checkSiblings(el) {
    var parent = el.parent().parent(),
      all = true;

    el.siblings().each(function() {
      return all = ($(this).children('input[type="checkbox"]').prop("checked") === checked);
    });

    if (all && checked) {
      parent.children('input[type="checkbox"]').prop({
        indeterminate: false,
        checked: checked
      });

      checkSiblings(parent);
    } else if (all && !checked) {
      parent.children('input[type="checkbox"]').prop("checked", checked);
      parent.children('input[type="checkbox"]').prop("indeterminate", (parent.find('input[type="checkbox"]:checked').lenght > 0));
      checkSiblings(parent);
    } else {
      el.parents("li").children('input[type="checkbox"]').prop({
        indeterminate: true,
        checked: false
      });
    }
  }

  checkSiblings(container);
});

$(document).ready(function() {
  $("#tree .open").click(function(e) {
    e.stopPropagation();
    $(this).toggleClass("open closed");
  });
});



Aucun commentaire:

Enregistrer un commentaire