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

Can I change states when using Dragula? #31

Open
vanjaw opened this issue May 23, 2018 · 1 comment
Open

Can I change states when using Dragula? #31

vanjaw opened this issue May 23, 2018 · 1 comment

Comments

@vanjaw
Copy link

vanjaw commented May 23, 2018

Hi!
I’m trying to use Dragula to implement a drag-and-drop exercise in our web application. The problem I’ve encountered is that we can’t change states from within the built-in Dragula functions. In the example further down I have a counter “counts” that counts each element that is dragged correctly. The problem is in the if-statement were I’ve written /* the following line is not working */, here I would like to change states.

The problem is that I can’t use “this” and I can’t find anyway to make my code rerender from the Dragula function…

Do you have any idea on how to solve this problem?


Example:

dragulaCreator = (container) => {
let drake = Dragula([container, $('drop-target1'), $('drop-target2')])

   drake.on('drop', function(el, target){
    if ((el == $('drag-elements1'))&&(target == $('drop-target1'))){
     
           /* the following line is not working */
           this.setState({endExercise: true})
          }
    else {
           drake.cancel();
    }
 }

}

@paddotk
Copy link

paddotk commented Jun 20, 2019

Is the this keyword the issue? With arrow functions that shouldn't be a problem, otherwise you'd have to bind it.
If dragulaCreator = (container) => {} works (and so you're using ES6) then you should do the same with the drop event handler:
drake.on('drop', (el, target) => {}

NB I wonder if comparing js DOM elements to jQuery selectors is assured to work..

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

No branches or pull requests

2 participants