Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TreeSelect when tree select child is pre selected the parent doesn't mark as partial selected #14499

Open
avim101 opened this issue Jan 8, 2024 · 6 comments
Labels
Resolution: Help Wanted Issue or pull request requires extra help and feedback
Milestone

Comments

@avim101
Copy link

avim101 commented Jan 8, 2024

Describe the bug

when tree select child is pre selected the parent doesnt mark as partial selected

Environment

primeng latest demo

Reproducer

https://stackblitz.com/edit/n5rewa?file=src%2Fapp%2Fdemo%2Ftree-select-reactive-forms-demo.ts

Angular version

17.0.5

PrimeNG version

17.3.1

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

18.18.0

Browser(s)

all

Steps to reproduce the behavior

  1. add options to treeSelect
  2. set selected node

Expected behavior

parent of the selected node should shown as partial selected [-]

@avim101 avim101 added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Jan 8, 2024
@mehmetcetin01140 mehmetcetin01140 added Type: Bug Issue contains a bug related to a specific component. Something about the component is not working and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Jan 11, 2024
@avim101
Copy link
Author

avim101 commented Feb 26, 2024

Hello @mehmetcetin01140 ,
just checking in for any updates on this issue

@pyrobirb
Copy link

pyrobirb commented Mar 5, 2024

Hello @mehmetcetin01140 , just checking in for any updates on this issue

I found a temporary solution (unsure of the consequences) but it worked for me..
but I have to set partialselected manually like this on ngModelChange:

    this.nodes = [ ...this.nodes.map(u => ({ ...u, partialSelected: !!selected?.find(x => x.parent?.key == u.key) })) ]

Override the resetPartialSelected method with something prevents it from executing.

Original (in primeng-treeselect.mjs):

resetPartialSelected(nodes = this.options){
        if (!nodes) {
            return;
        }
        for (let node of nodes) {
            node.partialSelected = false;
            if (node.children && node.children?.length > 0) {
                this.resetPartialSelected(node.children);
            }
        }
    }

Fix (applied in main.ts):

TreeSelect.prototype.resetPartialSelected = function(nodes = null){
       //
    }

@GitHubStan
Copy link

@avim101 will you please update this bug with a title that reflects the issue?

This is an issue for my team. Please fix.

@avim101 avim101 changed the title Component: TreeSelect TreeSelect when tree select child is pre selected the parent doesn't mark as partial selected Mar 28, 2024
@Jogonarr-3Pillar
Copy link

Any news on this bug please?

@miikakokkonen
Copy link

@pyrobirb, For me it was only necessary to set the partialSelected myself in ngModelChanges. It worked without touching TreeSelect.prototype

in template

<p-treeSelect
(ngModelChange)="treeselectChange($event)"
[options]="nodes"
selectionMode="checkbox">
. . . . 

in component.ts

treeselectChange(event: TreeNode[]) {
    event.forEach(x => {if (x.parent && !event.includes(x.parent) ) {x.parent.partialSelected = true}})
}

@mertsincan mertsincan added Resolution: Help Wanted Issue or pull request requires extra help and feedback and removed Type: Bug Issue contains a bug related to a specific component. Something about the component is not working labels Dec 25, 2024
@mertsincan mertsincan added this to the Future milestone Dec 25, 2024
@github-project-automation github-project-automation bot moved this to Review in PrimeNG Dec 25, 2024
Copy link

Due to PrimeNG team's busy roadmap, this issue is available for anyone to work on. Make sure to reference this issue in your pull request. ✨ Thank you for your contribution! ✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Help Wanted Issue or pull request requires extra help and feedback
Projects
Status: Review
Development

No branches or pull requests

7 participants