Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Draggable Input Elements

I am trying to make form elements draggable using jQuery UI. For example, buttons, checkboxes, textfields, etc. So far I have had no luck. Do you have any ideas how to accomplish this?

like image 657
awolfe Avatar asked Oct 09 '10 03:10

awolfe


2 Answers

Maybe 3 years too late but you could dispatch event and use following snippet for a more expected behaviour:

DEMO jsFiddle

$(".draggable").draggable({
    start: function (event, ui) {
        $(this).data('preventBehaviour', true);
    }
});
$(".draggable").find(":input").on('mousedown', function (e) {
    var mdown = new MouseEvent("mousedown", {
        screenX: e.screenX,
        screenY: e.screenY,
        clientX: e.clientX,
        clientY: e.clientY,
        view: window
    });
    $(this).closest('.draggable')[0].dispatchEvent(mdown);
}).on('click', function (e) {
    var $draggable = $(this).closest('.draggable');
    if ($draggable.data("preventBehaviour")) {
        e.preventDefault();
        $draggable.data("preventBehaviour", false)
    }
});
like image 95
A. Wolff Avatar answered Oct 02 '22 02:10

A. Wolff


Another option is to put it in wrapper and set this CSS for the input:

pointer-events: none;

You wan't be able to enter modify the input values.

like image 41
Max Avatar answered Oct 02 '22 03:10

Max