Commit b85f222d authored by Dave Methvin's avatar Dave Methvin

Don't fire change on an already-selected radio.

Thanks to Brandon Wallace (@bman654) for his code review. Also tweaks delegatetest.html output.
parent 3bd7bed3
...@@ -764,12 +764,20 @@ if ( !jQuery.support.changeBubbles ) { ...@@ -764,12 +764,20 @@ if ( !jQuery.support.changeBubbles ) {
setup: function() { setup: function() {
if ( rformElems.test( this.nodeName ) ) { if ( rformElems.test( this.nodeName ) ) {
// IE doesn't fire change on a checkbox/radio until blur; make it happen // IE doesn't fire change on a check/radio until blur; trigger it on click
// immediately by triggering our own change event now. // after a propertychange. Eat the blur-change in special.change.handle.
// Avoid double-firing change by eating it in special.change.handle. // This still fires onchange a second time for check/radio after blur.
if ( this.type === "checkbox" || this.type === "radio" ) { if ( this.type === "checkbox" || this.type === "radio" ) {
jQuery.event.add( this, "propertychange._change", function( event ) {
if ( event.originalEvent.propertyName === "checked" ) {
this._just_changed = true;
}
});
jQuery.event.add( this, "click._change", function( event ) { jQuery.event.add( this, "click._change", function( event ) {
simulate( "change", this, event, true ); if ( this._just_changed ) {
this._just_changed = false;
simulate( "change", this, event, true );
}
}); });
} }
return false; return false;
......
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>Change Tests</title> <title>Event Delegation Tests</title>
<script> <script>
var version = location.search && location.search.substr(1); var version = location.search && location.search.substr(1);
if ( version ) { if ( version ) {
...@@ -66,12 +66,6 @@ th, td { ...@@ -66,12 +66,6 @@ th, td {
<input type="checkbox" name="mycheckbox" id="check3" disabled="disabled"/> <input type="checkbox" name="mycheckbox" id="check3" disabled="disabled"/>
<label for="check3">check3</label> <label for="check3">check3</label>
</td> </td>
<td id="button">
<button name="mybutton1" id="button1">Button</button><br />
<button name="mybutton2" id="button2"><span>Button w/ child</span></button><br />
<button name="mybutton3" id="button3" disabled="disabled">Button Disabled</button><br />
<button name="mybutton4" id="button4" disabled="disabled"><span disabled="disabled">Button, child Disabled</span></button><br />
</td>
<td id="radio"> <td id="radio">
<input type="radio" name="myradio" id="radio1"/> <input type="radio" name="myradio" id="radio1"/>
<label for="radio1">Radio1</label><br/> <label for="radio1">Radio1</label><br/>
...@@ -90,7 +84,12 @@ th, td { ...@@ -90,7 +84,12 @@ th, td {
<td id="textarea"> <td id="textarea">
<textarea rows='2'></textarea> <textarea rows='2'></textarea>
</td> </td>
<td id="button">
<button name="mybutton1" id="button1">Button</button><br />
<button name="mybutton2" id="button2"><span>Button w/ child</span></button><br />
<button name="mybutton3" id="button3" disabled="disabled">Button Disabled</button><br />
<button name="mybutton4" id="button4" disabled="disabled"><span disabled="disabled">Button, child Disabled</span></button><br />
</td>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
...@@ -136,7 +135,7 @@ $("#version").text(version); ...@@ -136,7 +135,7 @@ $("#version").text(version);
$("#fileversion").text($.fn.jquery); $("#fileversion").text($.fn.jquery);
// Events we want to track in row-order // Events we want to track in row-order
var events = "bind-change live-change on-change bind-propertychange live-beforeactivate live-focusin bind-focus live-keydown live-beforedeactivate live-focusout bind-blur live-click".split(" "), var events = "bind-change live-change on-change bind-propertychange live-beforeactivate live-focusin bind-focus live-beforedeactivate live-focusout bind-blur live-click live-keydown".split(" "),
counter = 0; counter = 0;
blinker = function(event){ blinker = function(event){
if ( !counter ) { if ( !counter ) {
......
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