1

I'm using the asmselect plugin to allow users to select & order multiple items from a select box.

I only want to enable the submit button when the user has made a change. The following works, but change does not get called when sorting the selected elements:

<script type="text/javascript">
  $(document).ready(function() {
    $("select[multiple]").asmSelect({
      addItemTarget: 'bottom',
      highlight: false,
      hideWhenAdded: true,
      sortable: true
    });
    // track changes with our own event
    $("#mySelect").change(function(e, data) {
      $("#submit").removeAttr("disabled");

      // if it's a sort or an add, then give it a little color animation to highlight it
      if (data.type != 'drop') data.item.animate({ 'backgroundColor': '#ffffcc' }, 20, linear', function() {
        data.item.animate({ 'backgroundColor': '#dddddd' }, 500);
    });
  });
}); 
</script>

The select & submit:

<select id="mySelect" multiple="multiple" name="mySelect[]" title="Select Elements">
  <% foreach (var item in Model)
     { %>
  <option <%= item.Selected ? "selected=selected" : "" %> value="<%= Html.Encode(item.ID) %>">
    <%= Html.Encode(item.Text) %></option>
  <% } %>
</select>
<input type="submit" value="Save" id="submit" disabled="disabled"  />

How can I enable the submit when selected elements are sorted?

chris
  • 36,094
  • 53
  • 157
  • 237

2 Answers2

1

You need to change asm function as below:

function makeSortable() 
{
    // make any items in the selected list sortable
    // requires jQuery UI sortables, draggables, droppables

    $ol.sortable({
        items: 'li.' + options.listItemClass,
        handle: '.' + options.listItemLabelClass,
        axis: 'y',
        update: function(e, data) 
        {
            var updatedOptionId;

            $(this).children("li").each(function(n) 
            {
                //$option = $('#' + $(this).attr('rel'));
                // i'm not sure what this is here for as the return will break ordering
                //if($(this).is(".ui-sortable-helper")) 
                {
                //   updatedOptionId = $option.attr('id');
                //   return;
                //
                }

                //$original.append($option);
                $original.append($('#' + $(this).attr('rel')));
            });

            //we want to trigger change event always, even if it is only the order that has been changed.
        //if(updatedOptionId) triggerOriginalChange(updatedOptionId, 'sort');
            triggerOriginalChange(updatedOptionId, 'sort');
        }
    }).addClass(options.listSortableClass);
}
Lee Taylor
  • 7,761
  • 16
  • 33
  • 49
davo
  • 11
  • 1
0

It seems that with older versions of jquery/jquery-ui, an additional event was triggered for an item with ui-sortable-helper attribute. It

Try my updated version of asmselect. See code and example here

jogaco
  • 712
  • 8
  • 25
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Mihai Iorga Sep 28 '12 at 11:49