0

I load two different components (A,B), where i can drag and drop elements from A to B.

Is it possible to trigger a "self-submit" on component B and pass arguments when the drag-target container is changed? Thanks in advance.

Edit 1: The components are very simple solutions, A displays a list which elements can be dragged (and dropped to B), B is empty in the beginning. I want to achieve that if en element is dropped into B, informations on the element are passed to the controller.

Edit 2: Meanwhile I am able to trigger an event when the element is dropped. I used a small Drag-and-Drop script called Dragula (http://bevacqua.github.io/dragula/) - the event is triggered like this:

dragula([document.querySelector(".draggable"),document.querySelector(".drag-target")]).on("drop", function () { console.log("This Works!");});
bevacqua
  • 43,414
  • 51
  • 157
  • 277
Rockbot
  • 895
  • 1
  • 6
  • 24
  • 1
    You need to add more info into your question. What are those two components ? Is it a JavaScript related question? You should add a tag for that. Could you provide some code and further information about your question? – Diogo Martins May 12 '15 at 05:27
  • @DiogoMartins You have been right, in the end it was a JavaScript related question. – Rockbot May 13 '15 at 10:54

2 Answers2

1

You can answer to your drag event with something like:

web2py_component("/app/default/comp_b.load?yourpar=1","comp_b_id");

where comp_b_id is the id of your component_b without #

Massimiliano
  • 66
  • 1
  • 3
0

With Massimilianos hint and this answer I came up with this solution:

Component A (where the drag starts) now contains this script:

<script>
    /* Provides Drag and Drop functionality */
    d = dragula([document.querySelector(".drag-start"), document.querySelector(".drag-target")]);
    d.on('drop', function(el) {
        var test1, test2, id;
        test1 = 'test1'; /* Some information */
        id = $('.drag-target').attr('id'); /* The target ID */
        /* Pass data to the controller */
        $.post("{{=URL('controller', 'function')}}"+"/"+test1);
        /* Reload data to the target id */
        x = web2py_component("/app/controller/function.load"+"/"+id);
    });
</script>
Community
  • 1
  • 1
Rockbot
  • 895
  • 1
  • 6
  • 24