Skip to content

Commit

Permalink
Bug jquery#2551 select.val() broken in IE after form.reset()
Browse files Browse the repository at this point in the history
  • Loading branch information
rwaldron committed Feb 10, 2011
1 parent 78fc79f commit 26bc7ac
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ jQuery.fn.extend({
}
}

// Fixes Bug #2551 -- select.val() broken in IE after form.reset()
if ( one && !values.length && options.length ) {
return jQuery( options[ index ] ).val();
}

return values;
}

Expand Down
20 changes: 20 additions & 0 deletions test/unit/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,26 @@ test("val(Function) with incoming value", function() {
equals( jQuery("#select1").val(), "4", "Should be possible to set the val() to a newly created option" );
});

// testing if a form.reset() breaks a subsequent call to a select element's .val() (in IE only)
test("val(select) after form.reset() (Bug #2551)", function() {
expect(3);

jQuery('<form id="kk" name="kk"><select id="kkk"><option value="cf">cf</option><option value="gf">gf</option></select></form>').appendTo("#main");

jQuery("#kkk").val( "gf" );

This comment has been minimized.

Copy link
@csnover

csnover Feb 11, 2011

ummmmmmmm.


document.kk.reset();

equal( jQuery("#kkk")[0].value, "cf", "Check value of select after form reset." );
equal( jQuery("#kkk").val(), "cf", "Check value of select after form reset." );

// re-verify the multi-select is not broken (after form.reset) by our fix for single-select
same( jQuery('#select3').val(), ['1', '2'], 'Call val() on a multiple="multiple" select' );

jQuery("#kk").remove();
});


var testAddClass = function(valueObj) {
expect(5);
var div = jQuery("div");
Expand Down

0 comments on commit 26bc7ac

Please sign in to comment.