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

[p-tree] event.accept() not available on first drop #10093

Closed
leifjones opened this issue Apr 9, 2021 · 1 comment
Closed

[p-tree] event.accept() not available on first drop #10093

leifjones opened this issue Apr 9, 2021 · 1 comment
Assignees
Labels
LTS-FIXED-9.2.6 Fixed in PrimeNG LTS 9.2.6 LTS-FIXED-10.1.1 Fixed in PrimeNG LTS 10.1.1 Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@leifjones
Copy link

leifjones commented Apr 9, 2021

Thank you for the fix of #9991 with the release of 11.3.2. However, we're blocked by a related issue:

Even though, the event is now triggered. The first fire of the event doesn't have an accept() method. Thus our current implementation's attempt to utilize that method throws an error.

I'm submitting a ... (check one with "x")

[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

Plunkr Case (Bug Reports)
https://stackblitz.com/edit/primeng-treedragdrop-demo-4bbf54?file=src%2Fapp%2Fapp.component.ts
2021-04-09-no-accept-method

Current behavior

  1. The accept() method is not present the first time we drop the item. (It is there the second time we drop the item.)
  2. Apparently event.accept() does get called on/before/after this first drop to an empty list (Evidence: nodes get removed from source and added to target) event though it's not triggered by/accessible to the onDrop function.

Expected behavior

  1. The event.accept() is present on the event on the first drop.
  2. If the user onDrop method we provide, doesn't call the event.accept() method, the dropped node does not leave the source and get added to the target.

Minimal reproduction of the problem with instructions

See stackblitz and gif above

What is the motivation / use case for changing the behavior?

We need to:
a. validate the note and NOT accept() if criteria aren't met
b. copy and restore the dragged item in the source list before accept()
c. change the type of the dropped node

onDrop(event) {
  try {
    //
    const tentativeParent = // custom logic utilizing event.dragNode, event.dropNode

    // validation
    if (failureCondition) {
      // tell user
      return; // don't accept()
    }

    // copy and restore in source
    const copy: MyClass = new MyClass(event.dragNode);
    this.listOfSourceNodes.push(copy);
    this.listOfSourceNodes.sort((a, b) => this.mySourceNodeSorter(a, b));

    // approve drop
    event.accept();

    // transform
    event.dragNode.parentMyValue = tentativeParent.myValue;
    event.dragNode.draggable = true;
    event.dragNode.type = 'myTemplateString';
    tentativeParent.expanded = true;
  } catch (error) {
    // Report error
  }
}

Please tell us about your environment:

Windows 10, Visual Studio Code, NPM 7.9

  • Angular version: 11.2.9
  • PrimeNG version: 11.3.2
  • Browser: Only tried on Chrome 89
  • Language: TypeScript 4.0.5

  • Node (for AoT issues): node --version = 14.15.3

@yigitfindikli yigitfindikli self-assigned this Apr 10, 2021
@yigitfindikli yigitfindikli added the Status: Pending Review Issue or pull request is being reviewed by Core Team label Apr 10, 2021
@yigitfindikli yigitfindikli added this to the 11.4.0 milestone Apr 10, 2021
@leifjones leifjones changed the title event.accept() not available on first drop [p-tree] event.accept() not available on first drop Apr 10, 2021
leifjones pushed a commit to leifjones/primeng that referenced this issue Apr 12, 2021
@yigitfindikli yigitfindikli added Type: Bug Issue contains a bug related to a specific component. Something about the component is not working LTS-PORTABLE and removed Status: Pending Review Issue or pull request is being reviewed by Core Team labels Apr 12, 2021
@leifjones leifjones mentioned this issue Apr 12, 2021
@yigitfindikli
Copy link
Contributor

Fixed in 4a275dd

@yigitfindikli yigitfindikli added LTS-FIXED-10.1.1 Fixed in PrimeNG LTS 10.1.1 LTS-FIXED-9.2.6 Fixed in PrimeNG LTS 9.2.6 and removed LTS-PORTABLE labels Apr 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LTS-FIXED-9.2.6 Fixed in PrimeNG LTS 9.2.6 LTS-FIXED-10.1.1 Fixed in PrimeNG LTS 10.1.1 Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

No branches or pull requests

2 participants