0
votes

Scenario: A draggable DIV element containing a select dropdown Draggable has a clone helper. Select an option on the dropdown. When dragging, the clone helper does not retain the newly selected option. Instead, it uses the original option that was selected when the element was loaded.

Example:

http://jsfiddle.net/eg3bv/1/

html code:

<div class="master">
    <div class="draggable-container">

        <div class="select-container">
            <select class="select">
                <option value="value 1">Value 1</option>
                <option value="value 2">Value 2</option>
                <option value="value 3">Value 3</option>
            </select>
        </div>
    </div>

</div>

Javascript:

$( '.draggable-container' ).draggable({
    disabled: false,
    connectToSortable: ".sortable-container",
    helper: "clone",
    revert: "invalid",
    opacity: 0.35
});

Expected behavior: the clone helper should keep the newly selected option

The only way I see at this point is to add a function to the drag event that captures the original element's value then apply that value to the clone. But my instinct tells me jQuery should probably have a setting to keep the clone up-to-date with the original element changes.

Example:

http://jsfiddle.net/eg3bv/2/

$( '.draggable-container' ).draggable({
    disabled: false,
    connectToSortable: ".sortable-container",
    helper: "clone",
    revert: "invalid",
    opacity: 0.35,
     drag: function( event, ui ) {
         $( this ).find( '.select' ).each( 
             function(){ 
                 var indice = $( this ).val();
                 var u = ui.helper[0];
                 $( ui.helper[0] )
                 .find( '.select' ).each(         
                     function(){ 
                     $( this ).val( indice ); 
                 });
             });
     }
});

And finally, when I combine draggable and sortable by dragging to a different sortable element, the dropped clone reverts to the original selection -- even though I used the "drag" event to update the clone.

I might just create another function for the update on the sortable, but that just seems the longest path.

QUESTION: Is there any setting on jQuery-ui draggable that makes the clone helper preserve the select change?

1
possible duplicate of Clone isn't cloning select values, see also jQuery bug 1294.Nate Pinchot
Thanks Nate, it really is a duplicate.noderman

1 Answers

0
votes

Duplicate of

Clone isn't cloning select values

After further research I found this ticket in the JQuery bug tracker system which explains the bug and provides a work around. Apparently, it is too expensive to clone the select values so they won't fix it.

http://dev.jquery.com/ticket/1294

So each case will demand a specific workaround.