Commit 8a01c920 authored by Dave Methvin's avatar Dave Methvin

Fix #11382. #11764. Only prevent click events on disabled elements.

We don't want a disabled link/button to register delegated clicks, but we do want events like mouseover or custom events.

This is a compromise, there is no perfect solution. Well, the browsers could be consistent about direct vs. delegated events but *that's* not gonna happen.
parent 94e744ae
...@@ -388,8 +388,8 @@ jQuery.event = { ...@@ -388,8 +388,8 @@ jQuery.event = {
for ( cur = event.target; cur != this; cur = cur.parentNode || this ) { for ( cur = event.target; cur != this; cur = cur.parentNode || this ) {
// Don't process events on disabled elements (#6911, #8165) // Don't process clicks (ONLY) on disabled elements (#6911, #8165, #xxxx)
if ( cur.disabled !== true ) { if ( cur.disabled !== true || event.type !== "click" ) {
selMatch = {}; selMatch = {};
matches = []; matches = [];
jqcur[0] = cur; jqcur[0] = cur;
......
...@@ -1298,8 +1298,8 @@ test("Delegated events in SVG (#10791)", function() { ...@@ -1298,8 +1298,8 @@ test("Delegated events in SVG (#10791)", function() {
svg.remove(); svg.remove();
}); });
test("Delegated events in forms (#10844; #11145; #8165)", function() { test("Delegated events in forms (#10844; #11145; #8165; #xxxxx)", function() {
expect(3); expect(5);
// Alias names like "id" cause havoc // Alias names like "id" cause havoc
var form = jQuery( var form = jQuery(
...@@ -1334,11 +1334,20 @@ test("Delegated events in forms (#10844; #11145; #8165)", function() { ...@@ -1334,11 +1334,20 @@ test("Delegated events in forms (#10844; #11145; #8165)", function() {
form form
.append( '<button id="nestyDisabledBtn"><span>Zing</span></button>' ) .append( '<button id="nestyDisabledBtn"><span>Zing</span></button>' )
.on( "click", "#nestyDisabledBtn", function() { .on( "click", "#nestyDisabledBtn", function() {
ok( true, "enabled/disabled button with nesty elements" ); ok( true, "click on enabled/disabled button with nesty elements" );
})
.on( "mouseover", "#nestyDisabledBtn", function() {
ok( true, "mouse on enabled/disabled button with nesty elements" );
}) })
.find( "span" ).trigger( "click" ).end() // yep .find( "span" )
.trigger( "click" ) // yep
.trigger( "mouseover" ) // yep
.end()
.find( "#nestyDisabledBtn" ).prop( "disabled", true ).end() .find( "#nestyDisabledBtn" ).prop( "disabled", true ).end()
.find( "span" ).trigger( "click" ).end() // nope .find( "span" )
.trigger( "click" ) // nope
.trigger( "mouseover" ) // yep
.end()
.off( "click" ); .off( "click" );
form.remove(); form.remove();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment