Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Prevent ng-click from being called when sorting #174

Closed
pastinepolenta opened this issue May 14, 2014 · 8 comments
Closed

Prevent ng-click from being called when sorting #174

pastinepolenta opened this issue May 14, 2014 · 8 comments

Comments

@pastinepolenta
Copy link

I have this configuration:

<ul ui-sortable="sortableOptions">
   ....
      <a ng-click="doSometing()">

when I click on the link it works fine but sometimes the ng-click function is called even after I dragged/sorted. Is there a way to stop ng-click if dragging ?

@thgreasi
Copy link
Contributor

You can:

  • use a handle for the drag or
  • prevent ng-click by checking:
    • the classes that jquery-ui adds to the elements while dragging or
    • changing and checking a scope variable on drag start & stop
  • or by creating a transparent overlay or replacement item like discussed in sortable input #11

@pastinepolenta
Copy link
Author

Can you please explain point 1?
About point 2 as far as I see the ng-click method is fired only after the drag/drop terminate so the classes are already gone. I ve tried to set/unset a scope variable but the ng-click is not called regularly at every drag/drop but only sometimes (with no predictable behavior) so it was impossible to unset properly the scope var (I could set it on the drag callback but then it stays set if ng-click is not fired)

@thgreasi
Copy link
Contributor

Please use the search github provides.
The handle option was also discussed on #170 too.
Here is an example anyway...

@pastinepolenta
Copy link
Author

So, I d like to avoid the handle cause it ruins the design. On your 3rd point I see a reference that talks about the first point, unless I am missing something it still not a solution. About point 2 as I said does not seem to work.
Thanks for suggesting alternative solutions by I don't understand why ng-click and this sortable are conflicting and I d like to see them working together. Just be sure, is the unpredictable behavior I explained before normal in this kind of implementation or should I expect always either click or drag to be fired?

@pastinepolenta
Copy link
Author

update: looks like the issue happens in firefox, but not in chrome and is solved looking at this

@thgreasi
Copy link
Contributor

First of all, #11 has a link with an example of using overlays.
Can you can preventDefault or something on stop?
If not, then my best (hacky) solution at this point (since you say that ng-click fires after stop) is to:

  • Set a scope variable when a sorting starts/stops and
  • Inside ng-click ensure that at least 300ms have passed from the last sorting.
    This is similar to what most touch interfaces do.

@pastinepolenta
Copy link
Author

Thanks, I used setTimeout inside the stop callback to reset the scope variable to false anyway after 300 ms so I was able to trigger the ng click only if no sorting was previously executed.

@shyr
Copy link

shyr commented Jul 11, 2016

@stilllife00

helper : 'clone'

This really works for me in firefox. Thank you

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants