开发者

jqueryUI Sortable: handling .disableSelection() on form inputs

example: i have an un-ordered list containing a bunch of form inputs.

after making the ul .sortable(), I call .disableSelection() on the sortable (ul) to prevent text-selection when dragging an li item.

..all fine but I need to re/enable text-selection on the form inputs.. or the form is basically un-editable ..

i found a partial solution @ http://forum.jquery.com/topic/jquery-ui-sortable-disableselection-firefox-issue-with-inputs

  • enableSelection, disableSelection seem still to be un-documented: http://wiki.jqueryui.com/Core

a开发者_StackOverflow中文版ny thoughts?


solved . bit of hack but works! .. any comments how i can do this better?

apply .sortable() and then enable text-selection on input fields :


$("#list").sortable({
  stop: function () {
    // enable text select on inputs
    $("#list").find("input")
     .bind('mousedown.ui-disableSelection selectstart.ui-disableSelection', function(e) {
      e.stopImmediatePropagation();
    });
  }
}).disableSelection();

// enable text select on inputs
$("#list").find("input")
 .bind('mousedown.ui-disableSelection selectstart.ui-disableSelection', function(e) {
  e.stopImmediatePropagation();
});


A little improvement from post of Zack - jQuery Plugin

$.fn.extend({
    preventDisableSelection: function(){
        return this.each(function(i) {
            $(this).bind('mousedown.ui-disableSelection selectstart.ui-disableSelection', function(e) {
                e.stopImmediatePropagation();
            });
        });
    }
});

And full solution is:

$("#list").sortable({
  stop: function () {
    // enable text select on inputs
    $("#list").find("input").preventDisableSelection();
  }
}).disableSelection();

// enable text select on inputs
$("#list").find("input").preventDisableSelection();


jQuery UI 1.9

$("#list").sortable();
$("#list selector").bind('click.sortable mousedown.sortable',function(e){
    e.stopImmediatePropagation();
});

selector = input, table, li....


I had the same problem. Solution is quite simple:

$("#list").sortable().disableSelection();
$("#list").find("input").enableSelect();


The following will disable selection for the entire document, but input and select elements will still be functional...

function disableSelection(o) {
  var $o = $(o);
  if ($o.find('input,select').length) {
    $o.children(':not(input,select)').each(function(x,e) {disableSelection(e);});
  } else {
    $o.disableSelection();
  }
}
disableSelection(document);

But note that .disableSelection has been deprecated by jquery-ui and will someday go away.


EASY! just do:

$( "#sortable_container_id input").click(function() { $(this).focus(); });

and replace "sortable_container_id" with the id of the element that is the container of all "sortable" elements.


Quite old, but here is another way:

$('#my-sortable-component').sortable({
    // ...
    // Add all non draggable parts by class name or id, like search input texts and google maps for example
    cancel: '#my-input-text, div.map',
    //...
}).disableSelection();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜