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

Howto read DropTo option value for a specific board? #144

Closed
bairog opened this issue Oct 8, 2021 · 6 comments
Closed

Howto read DropTo option value for a specific board? #144

bairog opened this issue Oct 8, 2021 · 6 comments
Labels

Comments

@bairog
Copy link

bairog commented Oct 8, 2021

Hello and thank you for your awesome library.
As I can see dropEl callback fires even if item cannot be dragged to the target board (DragTo option of the source board doesn't have target board Id in it). I need to identify such situations (and don't perform all logic that is called in case of "allowed" drag).
I've started with the following code but I have no idea howto read DropTo option value here (I pass an extra jKanban value in my function because I need it to find a board):

function onDropEl(jKanban, el, target, source, sibling) {
    //FIRST variant to get targetBoardId
    var targetBoardId = target.parentElement.getAttribute('data-id');

    //SECOND variant to get targetBoardId - which of two is the correct one???
    var targetBoardId2 = target.parentElement.dataset.id;

    var targetBoard = jKanban.findBoard(targetBoardId);
   //Howto read DropTo option value here??? 
  
}
@xscode-auto-reply
Copy link

Thanks for opening a new issue. The team has been notified and will review it as soon as possible.
For urgent issues and priority support, visit https://xscode.com/riktar/jkanban

@bairog
Copy link
Author

bairog commented Oct 16, 2021

@marcosrocha85 maybe you can help me and answer some of that questions?

@marcosrocha85
Copy link
Contributor

@bairog you can find a lot of others past "problems" in Closed issues. I suggest you to take a look and try to figure out if some solution fits your needs. For instance, look at this #22.

@bairog
Copy link
Author

bairog commented Oct 18, 2021

I suggest you to take a look and try to figure out if some solution fits your needs. For instance, look at this #22.

Thank you I've used your code sample

var allowedBoards = [];
jkanban.options.boards.map(function (board) {
     if (board.id === $(source.parentElement).data("id")) {
          board.dragTo.map(function (_board) {
               if (allowedBoards.indexOf(_board) === -1) {
                    allowedBoards.push(_board);
               }
          });

          return allowedBoards[0];
     }

     return allowedBoards[0];
});

if (allowedBoards.length > 0 && allowedBoards.indexOf($(target.parentElement).data("id")) === -1) {
       kanban.drake.cancel(true);
       return;
}

but slightly modified and simplified it:

var allowedBoards = jkanban.options.boards.filter(b => b.id === source.parentElement.dataset.id)[0].dragTo;

if (allowedBoards.indexOf(target.parentElement.dataset.id) === -1) {
        jkanban.drake.cancel(true);
        return;
}

@marcosrocha85
Copy link
Contributor

I suggest you to take a look and try to figure out if some solution fits your needs. For instance, look at this #22.

Thank you I've used your code sample

var allowedBoards = [];
jkanban.options.boards.map(function (board) {
     if (board.id === $(source.parentElement).data("id")) {
          board.dragTo.map(function (_board) {
               if (allowedBoards.indexOf(_board) === -1) {
                    allowedBoards.push(_board);
               }
          });

          return allowedBoards[0];
     }

     return allowedBoards[0];
});

if (allowedBoards.length > 0 && allowedBoards.indexOf($(target.parentElement).data("id")) === -1) {
       kanban.drake.cancel(true);
       return;
}

but slightly modified and simplified it:

var allowedBoards = jkanban.options.boards.filter(b => b.id === source.parentElement.dataset.id)[0].dragTo;

if (allowedBoards.indexOf(target.parentElement.dataset.id) === -1) {
        jkanban.drake.cancel(true);
        return;
}

Nicely done!!! At that time I wasn't able to use filter (I can't remember why). Please close the issue if your problem was solved. I suggest you to create different issues for different questions.

@bairog
Copy link
Author

bairog commented Oct 18, 2021

Please close the issue if your problem was solved. I suggest you to create different issues for different questions.

Closed this one as my DropTo issue is solved now. Created separate issues: #148 for ItemHover and #149 for AddForm

@bairog bairog closed this as completed Oct 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants