I'm creating a day planner using jquery, draggable and droppable.
When a job is dragged from the unassigned column into a hour time slot, the original draggable item is removed, and a new div is placed into page, with the job details.
This newly created div block of code, has all the parameters in it to make it draggable . When it's rendered on the page load, these assigned jobs are draggable .
It's only when they are created on the fly using javascript is something occurring that stops them from being dragged about.
When I create these new div tags on the fly with Javascript, is there something I need to do to tell the jquery that these new items are meant to be dragged?
(thanks in advance as always)
Steps
Every time a page is created from php any jobs inside #person1 are present when jquery is activated, making them draggable. It's only when the refresh and re-population of the innerHTML is ran are the items (#jobN or #jobN2) unable to be dragged
var createdContent = httpRequest.responseText;
jobcolp.innerHTML = createdContent;
Hopefully this makes the problem a little more clearer.
To make an object draggable set draggable=true on that element. Just about anything can be drag-enabled: images, files, links, files, or any markup on your page.
Using jQuery UI, we can make the DOM(Document Object Model) elements to drag anywhere within the view port. This can be done by clicking on the draggable object by mouse and dragging it anywhere within the view port. If the value of this option is set to false, it will prevent the DOM elements to be dragged .
Add the draggable property with the value of true to an element to make it draggable. The dragstart , drag , and dragend events fire on the draggable element. The dragenter , dragover , dragleave or drop events fire on the drop target.
Simply apply draggable to the newly created DIV. If the DIV is exactly the same, except for position, you could also not recreate it, but just reposition it. This would retain all of it's handlers.
// remove, reposition, reapply handlers
$('#jobN').remove().appendTo('#dayViewN').draggable();
or
// reposition, retain handlers
$('#jobN').appendTo('#dayViewN');
Rather than replacing the new div, why not disable the draggable?
$(element).draggable('disable');
Then when you want it to be draggable agian, use this
$(element).draggable('enable');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With