how to deselect a node from controller?
i was reading the documentation and did fair amount of research but could not find a way to programatically deselect a node.
My Scenario:
When user 'left click' a node, a form template needs to show up right below the value. But since it is still part of the node, when user tries to click inside the form, the "node selection" event fires again, triggering the code to select node again.
my template:
<tree [tree]="tree" #treeComponent
(menuItemSelected)="onMenuItemSelected($event)"
(nodeMoved)="handleMoved($event)"
(nodeRenamed)="handleRenamed($event)"
(nodeRemoved)="handleRemoved($event)"
(nodeSelected)="handleSelected($event)"
(nodeCreated)="handleCreated($event)">
<ng-template let-node>
<p [ngClass]="{'wfTrigger-query': node.id === 'trigger'}" [innerHTML]="node.value"></p>
<div class="tree-form-container" *ngIf="node.showForm"> <-------- node.showForm is the flag
<div class="form-group">
<button type="button" class="close pull-right" aria-label="Close" (click)="handleClosingContent(node)">
<i class="fa fa-times"></i>
</button>
<div>
<input type="text" id="description" name="description" class="form-control" [(ngModel)]="node.value"/>
</div>
</div>
</div>
</ng-template>
</tree>
my component:
private handleSelected(e: any): void {
if (e && e.node && e.node.node && !e.node.node.showForm) {
e.node.node['showForm'] = true;
}
}
private handleClosingContent(node: any): void {
const oopNodeController = this.treeComponent.getControllerByNodeId(node.id);
if (node && node.showForm){
delete node['showForm'];
oopNodeController.deselect(); // looking for something like this as the 'handleSelected' is getting called again
}
}
by the way, thank you so much for a flexible yet powerful tree plugin.
@hotdog1987 Thanks! I will have a look - this actually might be a bug
@rychkog Thank you for a quick look at it. Is there a workaround/hack I can try at this moment? If this is an actual bug then the fix might not be available till it is released. Correct me if I'm wrong.
Thing is, we are deep into the project that this needs to be addressed.
Thank you.
@hotdog1987 I can add the deselect method on the weekend, also I think something like controller.disableSelection() and controller.enableSelection() might be useful. So new release will be there during the weekend.
@rychkog wow that would be awesome. Thanks alot!
@hotdog1987 I've released a new version with an API for allowing, forbidding node selection. Though, this feature is still absent in docs (will add later). You can have a look at the API in here. I hope it is intuitive enough. Looking forward to the feedback.
@rychkog Thank you so much for a weekend update. But, I'm little confused about the three new APIs that were introduced. We are seeking for an option to deselect a node from controller not forbidding selection. What is happening now is when I say controller.forbidSelection() everything works as it should but now the callback (nodeSelected)="handleSelected($event)" never gets triggered as it was forbidden from selection.
If I'm missing something, please let me know.
@hotdog1987 I've released a new version - rc.8
There you can (nodeUnselected)="handleUnselected($event)" and controller.unselect(). It triggers NodeUnselectedEvent
@rychkog Thank you alot!!!