Note that there are some explanatory texts on larger screens.

plurals
  1. POBlur event stops click event from working?
    primarykey
    data
    text
    <p>It appears that the Blur event stops the click event handler from working? I have a combo box where the options only appear when the text field has focus. Choosing an option link should cause an event to occur.</p> <p>I have a fiddle example here: <a href="http://jsfiddle.net/uXq5p/6/">http://jsfiddle.net/uXq5p/6/</a></p> <p>To reproduce:</p> <ol> <li>Select the text box</li> <li>Links appear</li> <li>Click a link</li> <li>The blur even occurs and the links disappear</li> <li>Nothing else happens.</li> </ol> <p>Expected behavior:</p> <p>On step 5, after blur occurs, the click even should also then fire. How do I make that happen?</p> <p><strong>UPDATE:</strong></p> <p>After playing with this for a while, it seems that someone has gone to great lengths to prevent an already-occurred click event from being handled if a blur event makes the clicked element Un-clickable.</p> <p>For example:</p> <pre><code>$('#ShippingGroupListWrapper').css('left','-20px'); </code></pre> <p>works just fine, but</p> <pre><code>$('#ShippingGroupListWrapper').css('left','-2000px'); </code></pre> <p>prevents the click event.</p> <p>This appears to be a bug in Firefox, since making an element un-clickable should prevent <strong><em>future</em></strong> clicks, but <strong><em>not</em></strong> cancel ones that have already occurred when it could be clicked.</p> <p>Other things that prevent the click event from processing:</p> <pre><code>$('#ShippingGroupListWrapper').css('z-index','-20'); $('#ShippingGroupListWrapper').css('display','none'); $('#ShippingGroupListWrapper').css('visibility','hidden'); $('#ShippingGroupListWrapper').css('opacity','.5'); </code></pre> <p>I've found a few other questions on this site that are having similar problems. There seem to be two solutions floating around:</p> <ol> <li><p>Use a delay. This is bad because it creates a race condition between the hiding and the click event handler. Its also sloppy.</p></li> <li><p>Use the <code>mousedown</code> event. But this isn't a great solution either since <code>click</code> <strong>is</strong> the correct event for a link. The behavior of <code>mousedown</code> is counter-intuitive from a UX perspective, particularly since you can't cancel the click by moving the mouse off the element before releasing the button.</p></li> </ol> <p>I can think of a few more.</p> <p>3.Use <code>mouseover</code> and <code>mouseout</code> on the <strong><em>link</em></strong> to enable/disable the blur event for the field. This doesn't work with keyboard tabing since the mouse is not involved.</p> <p>4.The best solution would be something like:</p> <pre><code>$('#ShippingGroup').blur(function() { if($(document.activeElement) == $('.ShippingGroupLinkList')) return; // The element that now has focus is a link, do nothing $('#ShippingGroupListWrapper').css('display','none'); // hide it. } </code></pre> <p>Unfortunately, <code>$(document.activeElement)</code> seems to always return the body element, not the one that was clicked. But maybe if there was a reliable way to know either 1. which element now has focus or two, which element caused the blur (not which element is blurring) from within the blur handler. Also, is there any other event (besides <code>mousedown</code>) that fires before blur?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload