aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/event.js12
-rw-r--r--test/unit/event.js29
-rw-r--r--test/unit/manipulation.js2
3 files changed, 40 insertions, 3 deletions
diff --git a/src/event.js b/src/event.js
index c3da76752..aeee603f7 100644
--- a/src/event.js
+++ b/src/event.js
@@ -263,7 +263,7 @@ jQuery.event = {
// Allow special events to draw outside the lines
special = jQuery.event.special[ type ] || {};
- if ( special.trigger && special.trigger.apply( elem, data ) === false ) {
+ if ( !onlyHandlers && special.trigger && special.trigger.apply( elem, data ) === false ) {
return;
}
@@ -523,7 +523,15 @@ jQuery.event = {
// Prevent triggered image.load events from bubbling to window.load
noBubble: true
},
-
+ click: {
+ // For checkbox, fire native event so checked state will be right
+ trigger: function() {
+ if ( jQuery.nodeName( this, "input") && this.type === "checkbox" && this.click ) {
+ this.click();
+ return false;
+ }
+ }
+ },
focus: {
delegateType: "focusin"
},
diff --git a/test/unit/event.js b/test/unit/event.js
index db968284f..f2f3cddd4 100644
--- a/test/unit/event.js
+++ b/test/unit/event.js
@@ -2831,6 +2831,35 @@ test("clone() delegated events (#11076)", function() {
clone.remove();
});
+test("checkbox state (#3827)", function() {
+ expect( 9 );
+
+ var markup = jQuery("<div><input type=checkbox><div>").appendTo("#qunit-fixture"),
+ cb = markup.find("input")[0];
+
+ jQuery(cb).on( "click", function(){
+ equal( this.checked, false, "just-clicked checkbox is not checked" );
+ });
+ markup.on( "click", function(){
+ equal( cb.checked, false, "checkbox is not checked in bubbled event" );
+ });
+
+ // Native click
+ cb.checked = true;
+ equal( cb.checked, true, "native - checkbox is initially checked" );
+ cb.click();
+ equal( cb.checked, false, "native - checkbox is no longer checked" );
+
+ // jQuery click
+ cb.checked = true;
+ equal( cb.checked, true, "jQuery - checkbox is initially checked" );
+ jQuery( cb ).click();
+ equal( cb.checked, false, "jQuery - checkbox is no longer checked" );
+
+ // Handlers only; checkbox state remains false
+ jQuery( cb ).triggerHandler( "click" );
+});
+
test("fixHooks extensions", function() {
expect( 2 );
diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js
index f08e7bd90..1d0dc4538 100644
--- a/test/unit/manipulation.js
+++ b/test/unit/manipulation.js
@@ -100,7 +100,7 @@ var testWrap = function(val) {
ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
jQuery(checkbox).wrap(val( "<div id='c1' style='display:none;'></div>" ));
ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
- }).click();
+ }).prop( "checked", false )[0].click();
// using contents will get comments regular, text, and comment nodes
var j = jQuery("#nonnodes").contents();