jquery asmselect:更改未在排序上触发

时间:2010-02-26 15:02:34

标签: jquery-plugins asmselect

我正在使用asmselect插件来允许用户选择&从选择框中订购多个商品。

我只想在用户进行更改时启用提交按钮。以下工作,但在排序所选元素时不会调用更改:

<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>

选择&amp;提交:

<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"  />

如何在对所选元素进行排序时启用提交?

2 个答案:

答案 0 :(得分:1)

您需要更改asm功能,如下所示:

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

答案 1 :(得分:0)

对于旧版本的jquery / jquery-ui,似乎为具有ui-sortable-helper属性的项触发了另一个事件。它

试用我的asmselect更新版本。 See code and example here