I'm creating a simple form builder to play around with jQueryUI. I have a list of form elements, just as images, which I've made draggable, set to helper 'clone'. I also have a dropable area on which I've set the drop event to read the id of the dropped image and create an appropriate form element and append it to the droppable area. Once I've appended the new element I'm then setting it to be draggable. The problem is that despite the new elements having the class ui-draggable once draggable has been called on them they aren't draggable. I want to be able to drag them around once they have been created.
Here's the code: -
var itemCount = 1;
var idToAdd;
var itemToAdd;
$(document).ready(function(){
$(".draggable").draggable({
opacity:0.5,
helper: "clone"
});
$(".form_builder").droppable(
{
activeClass: "droppable_dragged",
drop: function(e, ui){
var dropped_item = ui.draggable;
switch($(dropped_item).attr("id")){
case "text_box":
idToAdd = "textBox" + itemCount;
itemToAdd = "<input id='" + idToAdd + "' type='text' />";
break;
case "text_area":
break;
case "radio":
idToAdd = "radio" + itemCount;
itemToAdd = "<input id='" + idToAdd + "' type='radio' />";
break;
case "check":
idToAdd = "check" + itemCount;
itemToAdd = "<input id='" + idToAdd + "' type='check' />";
break;
case "dropdown":
break;
case "file":
idToAdd = "file" + itemCount;
itemToAdd = "<input id='" + idToAdd + "' type='file' />";
break;
case "button":
idToAdd = "button" + itemCount;
itemToAdd = "<input id='" + idToAdd + "' type='submit' />";
break;
}
itemCount++;
$(this).append(itemToAdd);
$("#" + idToAdd).draggable();
}
});
});