I'm using jquery Draggables with a Sortable. I have a list of elements on the left that I need to drag and drop into different divs on the right. It's possible to put the the same items from the left into multiple boxes, so I used helper: "clone." All works well until I need to get a reference to the new element that was cloned in the receive event so I can add a click handler to it.
I need a reference to the new element!
<div>
<div style="float: left; width: 300px;">
<div id="FieldList">
<h2>Loading</h2>
</div>
<input type="button" name="cmdTest" id="cmdTest" value="Test" />
</div>
<div style="float: right; width: 300px;">
<div>
<div>Select Columns</div>
<div class="Toolbar"></div>
<div id="SelectFields" class="DroppableField">
</div>
</div>
<div>
<div>Conditions</div>
<div class="Toolbar"></div>
<div class="DroppableField" style="background-color: Gray; height: 200px;">
</div>
</div>
<div>
<div>Order</div>
<div class="Toolbar"></div>
<div class="DroppableField" style="background-color: Gray; height: 200px;">
</div>
</div>
</div>
<div style="clear: both;">
</div>
</div>
Javascript:
$(document).ready(function () {
$(".DroppableField").sortable({
revert: true,
receive: function (ui, event) {
// ui.helper always seems to be null. Many of the other properties seem to reference the original item. I need the NEW ONE!!!
$(ui.helper).dblclick(function () {
});
}
});
$.ajax({
url: "/condition/getconditions",
data: {},
dateType: "json",
type: "POST",
success: function (data, successcode, jqXHR) {
var html = "";
for (var i = 0; i < data.length; i++) {
$("#FieldList").append("<div>" + data[i].Description + "</div>").find("div:last").data("fielddata", data[i]);
//html += ;
}
$("#FieldList div").draggable({
connectToSortable: ".DroppableField",
helper: "clone",
revert: "invalid"
});
}
});
});
ui
andevent
switched around, it should bereceive: function (event, ui)
– Björn