primeng icon indicating copy to clipboard operation
primeng copied to clipboard

p-tree validateDrop thow error in subscribe

Open oleksiyo opened this issue 7 years ago • 3 comments

[ x] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35

Current behavior I try to validation drag and drop in the tree as cancel dropping node according to a condition, but it doesn't work. when I use [validateDrop]="true" and event.accept(); inside subscribe I get next error "Cannot read property 'slice' of null" I don't know how but it works in debug if I oped developer tool in Chrome)))

Minimal reproduction of the problem with instructions my html: <p-tree #tree selectionMode="single" droppableNodes="true" draggableNodes="true" [validateDrop]="true" [contextMenu]="cm" [value]="companyTree" [(selection)]="selectedNode" (onNodeSelect)="nodeSelect($event)" (onNodeContextMenuSelect)="nodeContextMenuSelect($event)" (onNodeDrop)="onDrop($event)">

and ts file: onDrop(event) { if (my_condition) { this.myserve.update().subscribe( ok=>{ event.accept(); } error { .... } }

The error which I faced

image

it throws in tree.js: UITreeNode.prototype.processNodeDrop = function (dragNode) { var dragNodeIndex = this.tree.dragNodeIndex; this.tree.dragNodeSubNodes.splice(dragNodeIndex, 1); // ---- this line throws error .... }

What is the motivation / use case for changing the behavior? My business logic told me that some node can't be moved to another one node and before drop I would like to ask user permission via ConfirmDialog. User can cancel dropping node or approve.

Please tell us about your environment:

Windows10, WebStorm, NPM

Angular version: latest

PrimeNG version: 7.0.4

Browser: all

Language: all

Node (for AoT issues): node --version = v8.11.3

oleksiyo avatar Mar 14 '19 21:03 oleksiyo

Did you ever find a work around for this? I am running into the same error when using the confirmationservice to display a message that the user needs to confirm.

this.confirmationService.confirm({ message: 'This will MOVE the dragged element and all its children to the selected element. Continue?', accept: () => { event.accept(); //fails with splice error });

chetwatkins avatar Aug 29 '19 20:08 chetwatkins

Same here. event.accept() doesn´t works inside a subscribe

onDrop(event) { this.backendService.moveScript(request) .subscribe(response => { if (response) { event.accept() } ); } }

Essbante avatar Nov 01 '19 21:11 Essbante

Unable to replicate with PrimeNG 9, if the issue persists please create a new ticket with a test case reproducing the issue e.g. stackblitz or a github repo and it will be reviewed by our team once again.

cagataycivici avatar Mar 19 '20 10:03 cagataycivici