Note that there are some explanatory texts on larger screens.

plurals
  1. POhow do i put a draggable back in it's droppable using only code
    primarykey
    data
    text
    <p>The basic concept of my app is to map a group of pallets onto a truck. I have a page that allows the user to drag a draggable div "pallet" and place it in a droppable div "slot" on the truck. The weights for each row, left and right columns and the truck total weight are calculated on the fly. I then pass all of the information to a page to print a table of pallets and slots so an operator can then load the truck. The problem is restoring the load if the user only loads half the truck and then wants to come back at a latter time to finish. I know how to save any number of data points, but i cannot find a way to put the "pallets" back in their "slots" when i rebuild the page. </p> <p>Here are the div's for the pallets, some of the slots and the drop procedure (i'm not sure what else is needed)</p> <pre><code> //load the playpen with the pallets that belong on this truck for (var i = 0; i &lt; noPallets; i++) { $('&lt;div id="' + PalletIDs[i] + '"&gt;' + PalletIDs[i] + '&lt;br&gt;' + Storage[i] + ':' + Weights[i] + '&lt;/div&gt;').data('pallet', { ID: PalletIDs[i], Weight: Weights[i], columnNo: 0, rowNo: 0, tierNo:0 }).appendTo('#playpen').draggable({ containment: '#content', stack: '#playpen div', cursor: 'move', start: handlePalletStart, revert: true }); } // Create the pallet slots for truck left var words = ['C&lt;br&gt;one', 'C&lt;br&gt;two', 'C&lt;br&gt;three', 'C&lt;br&gt;four', 'C&lt;br&gt;five', 'C&lt;br&gt;six', 'C&lt;br&gt;seven', 'C&lt;br&gt;eight', 'C&lt;br&gt;nine', 'C&lt;br&gt;ten', 'C&lt;br&gt;eleven']; for (var i = 1; i &lt;= 11; i++) { position = 1000 + (i * 10) + 3 $('&lt;div id="' + position + '"&gt;' + words[i - 1] + '&lt;/div&gt;').data('position', { columnNo: 1, rowNo: i, tierNo: 3 }).appendTo('#truckleftC').droppable({ accept: '#playpen div', hoverClass: 'hovered', drop: handlePalletDrop }); } function handlePalletDrop(event, ui) { // this is the truck location we are about to drop into var columnNo = $(this).data('position').columnNo; var rowNo = $(this).data('position').rowNo; var tierNo = $(this).data('position').tierNo; // this is pallet information var palletID = ui.draggable.data('pallet').ID; var weight = ui.draggable.data('pallet').Weight; // if the pallet was already in a positio, we need to zero that position if (ui.draggable.data('pallet').columnNo != 0) { oldposition = ui.draggable.data('pallet').columnNo * 1000 + ui.draggable.data('pallet').rowNo * 10 + ui.draggable.data('pallet').tierNo; // alert(oldposition); for (var h = 0; h &lt;= 65; h++) { if (aryTWeight[h][0] == oldposition) { aryTWeight[h][1] = 0; } } } // set the position in the truck for this pallet ui.draggable.data('pallet').columnNo = columnNo; ui.draggable.data('pallet').rowNo = rowNo; ui.draggable.data('pallet').tierNo = tierNo; // set the weight for this position in the truck position = columnNo * 1000 + rowNo * 10 + tierNo // alert(position); for (var h = 0; h &lt;= 65; h++) { if (aryTWeight[h][0] == position) { aryTWeight[h][1] = weight; } } // alert(columnNo + ' : ' + rowNo + ' : ' + tierNo); // set the hidden text box with the palletid so data can be posted to next page for (var i = 0; i &lt; document.forms[0].elements.length; i++) { element = document.forms[0].elements[i]; if (element.name == oldposition) { element.value = 0; }; if (element.name == position) { element.value = palletID; }; } // set all of the weights for rows, columns and totals calcWeights(); ui.draggable.addClass('correct'); ui.draggable.position({ of: $(this), my: 'left top', at: 'left top' }); ui.draggable.draggable('option', 'revert', false); </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload