Hello! Thank you for a great module!! This is almost exactly what I'm looking for... close enough to use for now, but the behavior I'm looking for is called PROPAGATE_PRESERVING_CHECK in this demo: http://www.essi-lab.eu/projectsSites/lablib-checkboxtree/

That is, when selecting or unselecting a parent, all children become selected or unselected to match. If one of the children is unselected, the parent gets unselected. Selecting all the children selects the parent.

Unfortunately I'm not proficient enough in Java and jQuery to translate this code from Java to jQuery. Any pointers in the right direction would be appreciated! Thanks again!!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

BartK’s picture

I'll see what I can do. I'd like to get 1.0 out the door first before I start in on more features.

Bart

drifter’s picture

Version: 7.x-1.0-beta3 » 7.x-1.6
Status: Active » Needs review
FileSize
3.55 KB

Here's a patch against version 1.6 (wasn't sure if 2.x is stable right now) that will give you the option of selecting and unselecting children.

tnightingale’s picture

This extends #2, automatically unchecking of parents if a child item is unchecked.

BenStallings’s picture

Thank you both! Unfortunately the project I was going to use this for got postponed until spring, so I won't be in a position to test it for a few months. If someone else gets a chance to review the patch before me, that would be great. Thanks in advance.

dams_26’s picture

Yes ! need a new release please :)

scotty’s picture

#3 works, thank you!

Took me a while to apply. Instructions to use git apply from Making a Drupal patch with Git didn't work. Had to resort to patch -p1 <term_reference_tree-select_children-1189530-3.patch to apply. Probably something I don't understand.

The current patch doesn't support the Track list option, however. It doesn't correctly update the list of selected items displayed under the tree.

svdhout’s picture

Patch #3 works for me as well

Ghostthinker’s picture

Status: Needs review » Reviewed & tested by the community

#2 works perfect. Thank you, but could you make a patch against the dev version so it can go into the next version?

#3 @ tnightingale
I extended your version of unchecking the parent with this:

if (!checkbox.attr('checked') && !item.hasClass('select-parents')) {
  var parents = checkbox.parentsUntil('.form-type-checkbox-tree', 'li');
   parents.each(function(index, element) {
     $(element).find('input[type=checkbox]:first').removeAttr('checked');
   });
}

I added && !item.hasClass('select-parents') because when both select parents and children is active, it's better to leave the parent checked.
What do you think?

BartK’s picture

If I get a working patch on the 7.x-1.x git branch, I'll put it in.

BartK’s picture

Status: Reviewed & tested by the community » Active
BartK’s picture

People following this may want to check out the Cascading Selection option in the new version. It doesn't work *exactly* as described here, but it may be close enough for some people.

BenStallings’s picture

Thank you, BartK, yes, that's close enough for me.

sbandyopadhyay’s picture

Title: auto select children » unselect children
Version: 7.x-1.6 » 7.x-1.x-dev
Category: support » feature
Status: Active » Needs review

Thanks for the great module, BartK. Cascading Selection comes very close to implementing what was described in this post, but there's one thing missing: automatic unselecting of all children, regardless of whether or not they are checked. I've attached a patch that implements this exact functionality. When selected alongside Cascading Selection, this new feature works precisely as described above in the original post.

sbandyopadhyay’s picture

With the patch attached this time...

sbandyopadhyay’s picture

So I reviewed the original post again after posting my patch, and I realized that the two are not actually asking for and accomplishing the same thing. I apologize for not reading it more closely before I posted. I guess I've unintentionally hacked this thread for a different purpose. If anyone minds, please feel free to change it back to what it was before -- I'll open up a new issue and re-post my patch there.

The original post requests a system that has the parent's checked status reflect whether or not all the children are checked.

The Cascading Selection system has the children reflect the parent's checked status, but only if all the children were already set uniformly.

The patch in #14 creates a system which will "Force selection of parents". When enabled on its own, this system unchecks all children when a parent is unchecked. When enabled alongside Cascading Selection and Select Parents Automatically, this system forces parents to follow their children, but allows children to not have to follow their parents.

BenStallings’s picture

As the original poster, I have no objection to you hijacking the thread, since my needs have been met already. Thanks for asking.

Jelle_S’s picture

Status: Needs review » Needs work

The last submitted patch, 17: unselect-children-1189530-17.patch, failed testing.

BartK’s picture

I don't have time to test this myself, but if I can get some assurance from the community that this patch works without breaking anything, I'll merge it in and release a new version.

potassiumchloride’s picture

I am using Cascading Selection and am running into both of the needs described in this post, so I would be happy to test patches if I know which one(s) to test.

My use case:
1. Checking a parent checks all child terms. (works)
2. Checking all child terms checks the parent term. (does not work)
3. When all children are unchecked, the parent is unchecked. (does not work)
4. When a child term is unchecked, the parent is also unchecked (does not work)
5. The parent term does not appear checked unless ALL of the children are checked. (does not work)

Right now, I can check the parent term and all child terms are checked (1). Checking all child terms does not check the parent (2). Unchecking all child terms does not uncheck the parent (3). Checking a parent, then unchecking one of the child terms leaves the parent checked, and I want it to uncheck (4).

Ideally for our case, there would not be a situation where the parent term is checked unless all of the children are checked. I think this is what the poster in #15 described, a system that forces parents to follow their children, but allows children to not have to follow their parents. That post refers to a patch in #14.

@BartK Which patch did you want users to test? #17 has no comments so I'm not sure what issue it is expected to solve. Is it a reroll or update of #14? Or of #3? I'm happy to install and test as best I can, if you can tell me the best place to start.

potassiumchloride’s picture

alex_optim’s picture

Status: Needs work » Fixed

This behavior is only observed when all the child elements are selected. And that's right. When one of the children is not selected, this rule does not apply. Therefore, I see no reason to change the logic of work. Because everything is working right now.

alex_optim’s picture

Status: Fixed » Closed (works as designed)