Make sure that the correct value is being pulled from checkboxes in Webkit. Fixes...
[jquery.git] / test / unit / manipulation.js
index 8c3d1a5..9242ddd 100644 (file)
@@ -105,7 +105,7 @@ test("wrapAll(String|Element)", function() {
 
 // TODO: Figure out why each(wrapAll) is not equivalent to wrapAll
 // test("wrapAll(Function)", function() {
-//     testWrapAll(functionReturningObj);
+//     testWrapAll(functionReturningObj);
 // })
 
 var testWrapInner = function(val) {
@@ -130,7 +130,7 @@ test("wrapInner(String|Element)", function() {
 
 // TODO: wrapInner uses wrapAll -- get wrapAll working with Function
 // test("wrapInner(Function)", function() {
-//     testWrapInner(functionReturningObj)
+//     testWrapInner(functionReturningObj)
 // })
 
 var testUnwrap = function() {
@@ -251,7 +251,7 @@ var testAppend = function(valueObj) {
 }
 
 test("append(String|Element|Array<Element>|jQuery)", function() {
-  testAppend(bareObj);
+       testAppend(bareObj);
 });
 
 test("append(Function)", function() {
@@ -619,7 +619,7 @@ test("clone() on XML nodes", function() {
 }
 
 test("val()", function() {
-       expect(9);
+       expect(17);
 
        document.getElementById('text1').value = "bla";
        equals( jQuery("#text1").val(), "bla", "Check for modified value of input element" );
@@ -641,6 +641,33 @@ test("val()", function() {
 
        equals( jQuery('#option3e').val(), 'no value', 'Call val() on a option element with no value attribute' );
 
+       equals( jQuery('#option3a').val(), '', 'Call val() on a option element with no value attribute' );
+
+       jQuery('#select3').val("");
+       same( jQuery('#select3').val(), [''], 'Call val() on a multiple="multiple" select' );
+
+       var checks = jQuery("<input type='checkbox' name='test' value='1'/>").appendTo("#form")
+               .add( jQuery("<input type='checkbox' name='test' value='2'/>").appendTo("#form") )
+               .add( jQuery("<input type='checkbox' name='test' value=''/>").appendTo("#form") )
+               .add( jQuery("<input type='checkbox' name='test'/>").appendTo("#form") );
+
+       same( checks.serialize(), "", "Get unchecked values." );
+
+       equals( checks.eq(3).val(), "on", "Make sure a value of 'on' is provided if none is specified." );
+
+       checks.val([ "2" ]);
+       same( checks.serialize(), "test=2", "Get a single checked value." );
+
+       checks.val([ "1", "" ]);
+       same( checks.serialize(), "test=1&test=", "Get multiple checked values." );
+
+       checks.val([ "", "2" ]);
+       same( checks.serialize(), "test=2&test=", "Get multiple checked values." );
+
+       checks.val([ "1", "on" ]);
+       same( checks.serialize(), "test=1&test=on", "Get multiple checked values." );
+
+       checks.remove();
 });
 
 var testVal = function(valueObj) {
@@ -658,9 +685,9 @@ var testVal = function(valueObj) {
        jQuery("#select1").val(valueObj( 2 ));
        equals( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" );
 
-  jQuery("#select1").append("<option value='4'>four</option>");
-  jQuery("#select1").val(valueObj( 4 ));
-  equals( jQuery("#select1").val(), "4", "Should be possible to set the val() to a newly created option" );
+       jQuery("#select1").append("<option value='4'>four</option>");
+       jQuery("#select1").val(valueObj( 4 ));
+       equals( jQuery("#select1").val(), "4", "Should be possible to set the val() to a newly created option" );
 
        // using contents will get comments regular, text, and comment nodes
        var j = jQuery("#nonnodes").contents();