jQuery asmselect:更改不触发排序 [英] jquery asmselect: changes not firing on sort

查看:64
本文介绍了jQuery asmselect:更改不触发排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 asmselect 插件来允许用户选择&从选择框中订购多个项目.

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

我只想在用户进行更改后启用提交"按钮.可以执行以下操作,但是对选定元素进行排序时不会调用change:

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>

选择&提交:

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

推荐答案

您需要按以下方式更改asm函数:

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

这篇关于jQuery asmselect:更改不触发排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆