Search code examples
jqueryjquery-uijquery-ui-draggablejquery-ui-droppable

Jquery on drop remove helper


I use jquery draggable and jquery droppable , in draggable function I use helper clone, and when I drop the dragged element it should remove the clone and show another div, in the droppable place I have a div inside that is invisible and on drop it should be visible , this is my code

$('#external-events .fc-event').each(function() {
                        // store data so the calendar knows to render an event upon drop

                        // make the event draggable using jQuery UI
                        $(this).draggable({
                            helper:'clone',
                            zIndex: 999999,
                            containment: 'window',
                            appendTo:'body',
                            scroll: false,
                            revert: true,      // will cause the event to go back to its
                            revertDuration: 0,  //  original position after the drag
                            // start: function(){
                            //     $(this).fadeOut();
                            //
                            // },
                            // stop: function(){
                            //     $(this).fadeIn();
                            // }
                        });

                    });

and this is my droppable function

 $(to).droppable({

                drop: function ( event, ui ){
                 $("ui.draggable").clone().hide();
                    var avatar = '';
                    var user = ui.helper[0].id;
                    console.log("user", user);
                    var fullname = $('#'+user+' .fullName').text();
                    var hiddenInput = $('#'+user+' .userId').val();
                    console.log("ID: ", hiddenInput);
                    console.log(fullname);
                    $('#uname_here').text(fullname);
                    var userId = '#' + ui.helper[0].id + ' .userId';
                    $('.whenDropOwnerHideThis').hide();
                    $("div#dropedUser").show();
                    $('#dropUserForHeadOfProjectInput').val(hiddenInput);
                    $("#dropUserForHeadOfProject").removeClass('error_empty');
                    $("#drop_head_project").removeClass('error_empty');

                }
            });

like this it doesn't work, It shows errors

Uncaught Error: Syntax error, unrecognized expression: # .fullName

Solution

  • the problem was that I couldn't get the id correctly so this is how i get it now and it works fine ,

    var user = ui.helper.context.id;