最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Make text selectable in a textarea within a jQuery Sortable parent - Stack Overflow

programmeradmin1浏览0评论

I have a table whose body I've made sortable using jQuery UI's Sortable function. Within this sortable table, I have a textarea which allows the user to enter ments about a given table entry.

<table id="status">
    <thead>
        <tr>
            <th>Name</th>
            <th>Comment</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td class="dragHandle">Jason</td>
            <td><textarea class="mentBox"></textarea></td>
        </tr>
    </tbody>
</table>

And the javascript to make the table sortable (with a helper function for making tables sortable I found online)

// Return a helper with preserved width of cells
var fixHelper = function(e, ui) {
    ui.children().each(function() {
        $(this).width($(this).width());
    });

    return ui;
};

$("#status").sortable({
    helper: fixHelper,
    axis: 'y',
    handle: '.dragHandle'
}).disableSelection();

Text entry into this textarea works fine, however when I try to select text within the textarea, nothing happens. Even using Shift+Arrow Keys does not behave as I would expect.

How do I make a textarea's text selectable while still making the entire table sortable?

Already Attempted:

  • Doing a sortable "destroy" on the table when a textarea gets focus to try and temporarily allow selectability, but even after the destroy, text selection is still wonky.

  • Setting the 'handle' property of the sortable to make only the Name field sortable

  • Setting the 'disable' property of the sortable to disable when initiated from textareas

  • Capturing the mousedown/mouseup events in the textarea (or a div containing the textarea) and calling event.stopPropagation()

I have a table whose body I've made sortable using jQuery UI's Sortable function. Within this sortable table, I have a textarea which allows the user to enter ments about a given table entry.

<table id="status">
    <thead>
        <tr>
            <th>Name</th>
            <th>Comment</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td class="dragHandle">Jason</td>
            <td><textarea class="mentBox"></textarea></td>
        </tr>
    </tbody>
</table>

And the javascript to make the table sortable (with a helper function for making tables sortable I found online)

// Return a helper with preserved width of cells
var fixHelper = function(e, ui) {
    ui.children().each(function() {
        $(this).width($(this).width());
    });

    return ui;
};

$("#status").sortable({
    helper: fixHelper,
    axis: 'y',
    handle: '.dragHandle'
}).disableSelection();

Text entry into this textarea works fine, however when I try to select text within the textarea, nothing happens. Even using Shift+Arrow Keys does not behave as I would expect.

How do I make a textarea's text selectable while still making the entire table sortable?

Already Attempted:

  • Doing a sortable "destroy" on the table when a textarea gets focus to try and temporarily allow selectability, but even after the destroy, text selection is still wonky.

  • Setting the 'handle' property of the sortable to make only the Name field sortable

  • Setting the 'disable' property of the sortable to disable when initiated from textareas

  • Capturing the mousedown/mouseup events in the textarea (or a div containing the textarea) and calling event.stopPropagation()

Share Improve this question edited Apr 8, 2014 at 19:29 Greg 2,1731 gold badge22 silver badges23 bronze badges asked Oct 8, 2010 at 17:36 JaxJax 7,1704 gold badges29 silver badges39 bronze badges 1
  • Can you post your sortable JS? – methodin Commented Oct 8, 2010 at 17:46
Add a ment  | 

1 Answer 1

Reset to default 7

What's the reasoning for using disableSelection? That is the reason your textArea is not getting focus.

发布评论

评论列表(0)

  1. 暂无评论