fix for checkbox click event which now sets the checked state correctly.
This commit is contained in:
parent
8bd88b62dd
commit
748b3da785
|
@ -57,7 +57,8 @@
|
|||
* 2) Fix CSS2Properties support for parsing style attributes: get from raw node context.
|
||||
* 3) Fix CSS2Properties support for setting values: all properties have the same objmaps, wtf?
|
||||
* 4) Fix focus() which sets document.activeElement correctly for jQuery:focus
|
||||
*/
|
||||
* 5) Fix Input click() behavior for checkboxes. Warning: jQ's click() <-> DOM's click (checked value too late set)!
|
||||
**/
|
||||
(function() {
|
||||
|
||||
var oldEnvjsUriFn = Envjs.uri;
|
||||
|
@ -91,6 +92,16 @@
|
|||
|
||||
})(HTMLElement.prototype);
|
||||
|
||||
(function(input) {
|
||||
var oldClick = input.prototype.click;
|
||||
input.prototype.click = function() {
|
||||
if(this.type === "checkbox") {
|
||||
this.checked = !this.checked;
|
||||
}
|
||||
oldClick.apply(this, arguments);
|
||||
}
|
||||
})(HTMLInputElement);
|
||||
|
||||
(function(Input, Textarea, document) {
|
||||
var activeElement;
|
||||
function fixFocusForPrototype(element) {
|
||||
|
|
|
@ -37,6 +37,34 @@ describe("envjs fixes", function() {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Checkbox click events", function() {
|
||||
it("should set the state of the checkbox to checked if not checked when clicked", function() {
|
||||
$("#checkbox").click();
|
||||
expect($("#checkbox")).toBeChecked();
|
||||
});
|
||||
|
||||
it("should set the state of the checkbox to unchecked if checked when clicked", function() {
|
||||
$("#checkbox").attr('checked', true);
|
||||
$("#checkbox").click();
|
||||
expect($("#checkbox")).not.toBeChecked();
|
||||
});
|
||||
|
||||
it("should still fire the click event after clicking on a checkbox", function() {
|
||||
var clicked = false;
|
||||
$("#checkbox").click(function() {
|
||||
clicked = true;
|
||||
});
|
||||
|
||||
waitsFor(function() {
|
||||
return clicked;
|
||||
});
|
||||
$("#checkbox").click();
|
||||
runs(function() {
|
||||
expect(clicked).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("CSS2 style property support for parsing style attributes", function() {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
<form id="form">
|
||||
<input type="text" id="input" value="text"></input>
|
||||
<input type="checkbox" id="checkbox"></input>
|
||||
<textarea id="area"></textarea>
|
||||
<input type="submit" id="submit"></input>
|
||||
</form>
|
||||
|
|
Reference in New Issue