开发者

jquery asmselect: changes not firing on sort

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?


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);
}


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜