views:

231

answers:

2

I have a html textbox on which I've bound a function via jQuery to the paste event to prevent users pasting a value into the textbox. This functionality works well.

However it is possible to select some text from another textbox on the page and drag it into the textbox in which pastes are prevented. Is there a jQuery event that I can bind to that will prevent users dragging text into the texbox?

+1  A: 

Unfortunately, this is not possible.

SLaks
sure it is...but I'm not going to provide the solution...not even for a million rep bounty!
David Murdoch
Does it involve breaking into Redmond and 'tinkering' with some Source?
GenericTypeTea
Yes. Unfortunately there is one major drawback: besides copy/paste functionality being disabled on inputs --- that "teenie, tiny" modification may be all it takes to turn IE into skynet...could you image the devastation and the horror of IE taking over the world?!?
David Murdoch
+2  A: 

First of all you shouldn't prevent the user from being able to copy and paste or click and drag from one input to another. Most people despise the confirm email input box, and I'm one of them. Making it harder to fill it in will only serve to irritate your users.

However... warning hack alert...

You cannot block the built in browser functionality, however you could disable the text from being selected in the inputs you don't want to be dragged like follows:

OPTION 1:

$(document).ready(function () {

    // Get the control from which the drag should be disallowed
    var originator = $(".start");

    // Disable text selection
    if ($.browser.mozilla) {
        originator.each(function () { $(this).css({ 'MozUserSelect': 'none' }); });
    } 
    else if ($.browser.msie) {
        originator.each(function () { $(this).bind('selectstart.disableTextSelect', 
           function () { return false; }); });
    } 
    else {
        originator.each(function () { $(this).bind('mousedown.disableTextSelect', 
           function () { return false; }); });
    }

});

But, this would be REALLY annoying.

OPTION 2:

You could disable the confirmation box when the user is dragging an item:

$(document).ready(function () {

    // Get the control which dropping should be disallowed
    var originator = $("#emailBox");

    // Trap when the mouse is up/down
    originator.mousedown(function (e) {
        $("#confirmationBox").attr('disabled', 'disabled');
    });
    originator.mouseup(function (e) {
        $("#confirmationBox").attr('disabled', '');
    });

});

OPTION 3:

Do your user-base a favour and get rid of the confirmation box.

GenericTypeTea
You have no _idea_ how annoying this would be.
SLaks
@SLaks I certainly know exactly how annoying it would be. I've rewritten the answer especially for you.
GenericTypeTea
can you post option 3 as a separate answer? I'll +1 to that!
David Murdoch
Nah, I save my flip remarks for comments :P
GenericTypeTea
Boo. Yesterday someone posted "The one fix for all IE6 problems is to stop supporting IE6." as an answer to [this question](http://stackoverflow.com/questions/2773464/one-fix-for-all-ie6-problems) and has since been up-voted 35 times.
David Murdoch