Using jQuery, setting Draggable on an element prevents blur from firing when you click the draggable

Posted by Danno on Stack Overflow See other posts from Stack Overflow or by Danno
Published on 2009-11-12T19:27:20Z Indexed on 2010/05/04 23:48 UTC
Read the original article Hit count: 440

Using jQuery, when you set a blur event on a text box and set another element as draggable, when you click the draggable element, the blur event does not fire in FireFox. IE is a little better, you get the blur event but you don't get the click event on the draggable element.

If you don't specify the cancel: "" in the draggable constructor, you will get the blur event to fire, but then the element you want to drag is not draggable.

jQuery v1.3.2 jQuery UI v1.7.2

The console.log lines are for FireFox's FireBug plugin.

<HTML> 
    <HEAD> 
    	<TITLE>Blur/Click Workbench</TITLE> 
    	<script src="js/jquery.js" type="text/javascript" ></script>
    	<script src="js/ui/ui.core.js" type="text/javascript"></script>
    	<script src="js/ui/ui.draggable.js" type="text/javascript"></script>
    	<script type="text/javascript">	
function blurring() {
    console.log('1 - blurring - ' + $( this ).attr('id'));
}

function clicking() {
    console.log('2 - clicking - ' + $( this ).attr('id'));
}

$(document).ready(function() {
    $( ".draggableTool" ).draggable( { cancel: "" } );

    $( '.property' ).blur( blurring );
    $( '#labelContainer' ).click( clicking );
});
    	</script>
    </HEAD>
    <BODY>
    	<input type='text' class='property' id='tb1' />
    	<br />
    	<input type='text' class='property' id='tb2' />
    	<br />
    	<label class='draggableTool' id='labelContainer' style='height:20px;position:absolute;'>
    		<textarea id='taLabel' style='height:100%;background-color:white;border:1px solid grey;'>Label</textarea>
    	</label>
    </BODY>
</HTML>

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about jquery-ui