1

i have a page with 2 elements:

  1. a list of items with draggable method
  2. a lost of items with sortable method

i only allow dragging from list 1 to list 2, and that seems to work ok.

now, what i'm looking for is that when i drag item from list 1 to list 2 the newly created element will contain some different html then the element that was dragged. is that possible?

iv'e tried this approach but that does not seem to do to the job:

    $("#list_2").sortable({
        placeholder: "ui-state-highlight",
        cursor: "move",
        delay: 150,
        forcePlaceholderSize: true,
        opacity: 0.5,
        scrollSpeed: 40,
        receive: function( event, ui ) {
            ui.item.html(ui.item.find(".hide").html());
}
});
        $("#list_1").disableSelection();
        $(".draggable").draggable({
        connectToSortable: "#template_parts",
        helper: "clone",
        revert: "invalid",
        stop: function( event, ui ) {
    }
            });

any help shall be greatly appriciated

3
  • Can you add your html or make a jsfiddle.net with an example? Thanks Commented Nov 25, 2013 at 23:00
  • jsfiddle.net/jd8A7 Commented Nov 25, 2013 at 23:24
  • I can't get dragging from list 1 to list 2 to work in your fiddle. Your calling draggable on .draggable but I don't see anything with that class in your HTML.. Commented Nov 25, 2013 at 23:30

1 Answer 1

3
var received = false;
$(function() {
    $( ".draggable" ).draggable({
        connectToSortable: "#list_2"
    });
    $( "#list_2" ).sortable({
        receive: function(event,ui){
            received = true;
        },
        stop: function(event,ui){
            if(received){ 
                ui.item.css('color','blue');
                ui.item.html(ui.item.html()+' changed');
                received = false;
            }
        }
   });
   $( "#list_2" ).disableSelection();
});

Example

http://jsfiddle.net/jd8A7/4/

Sign up to request clarification or add additional context in comments.

3 Comments

@sd1sd1 please mark this answer as accepted it helped answer your question or give feedback. Thanks
hello trevor. actually, this is not what i meant. i have an html elemnent inside the ui but calling ui.item.html(ui.item.html().find(".div_name").html()); does not seem to work
i manageed to make my previous question work stop: function(event,ui){ if(received){ htm = ui.item.find(".hide").html(); ui.item.html(htm); received = false; } }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.