Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't have .val() return selected-but-disabled options, or selected o…
…ptions inside a disabled optgroup. Doesn't change the .val() returned for a disabled select. Fixes #3240, adapted from Nathan Hammond's patch there.
- Loading branch information
Showing
6 changed files
with
31 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
|
@@ -302,7 +302,7 @@ test("removeAttr(String)", function() { | ||
}); | }); | ||
|
|
||
test("val()", function() { | test("val()", function() { | ||
expect(17); | expect(20); | ||
|
|
||
document.getElementById('text1').value = "bla"; | document.getElementById('text1').value = "bla"; | ||
equals( jQuery("#text1").val(), "bla", "Check for modified value of input element" ); | equals( jQuery("#text1").val(), "bla", "Check for modified value of input element" ); | ||
|
@@ -329,6 +329,14 @@ test("val()", function() { | ||
jQuery('#select3').val(""); | jQuery('#select3').val(""); | ||
same( jQuery('#select3').val(), [''], 'Call val() on a multiple="multiple" select' ); | same( jQuery('#select3').val(), [''], 'Call val() on a multiple="multiple" select' ); | ||
|
|
||
same( jQuery('#select4').val(), [], 'Call val() on multiple="multiple" select with all disabled options' ); | |||
|
|||
jQuery('#select4 optgroup').add('#select4 > [disabled]').attr('disabled', false); | |||
same( jQuery('#select4').val(), ['2', '3'], 'Call val() on multiple="multiple" select with some disabled options' ); | |||
|
|||
jQuery('#select4').attr('disabled', true); | |||
same( jQuery('#select4').val(), ['2', '3'], 'Call val() on disabled multiple="multiple" select' ); | |||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jeresig
Member
|
|||
|
|||
var checks = jQuery("<input type='checkbox' name='test' value='1'/><input type='checkbox' name='test' value='2'/><input type='checkbox' name='test' value=''/><input type='checkbox' name='test'/>").appendTo("#form"); | var checks = jQuery("<input type='checkbox' name='test' value='1'/><input type='checkbox' name='test' value='2'/><input type='checkbox' name='test' value=''/><input type='checkbox' name='test'/>").appendTo("#form"); | ||
|
|
||
same( checks.serialize(), "", "Get unchecked values." ); | same( checks.serialize(), "", "Get unchecked values." ); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This test fails for all Webkit browsers listed on the testswarm http://swarm.jquery.org/job/225/. The cause seems to be that Webkit (different from all other browsers) returns
true
for thedisabled
attribute of alloption
s which are immediate childrens of a disabledselect
. Even when the options itself hasn't thedisabled
attribute set explicitlyThis is the reason why the option with id
option4d
is missing from the actual result. The only workaround I could find is to use thegetAttribute()
function in Safari (didn't test if this also works in the other Webkit based browsers). Which returnsnull
if thedisabled
attribute isn't set orfalse
and an empty string if it is set totrue
/disabled
. Whileoption.disabled
always returnstrue
if the parentselect
is disabled not matter if the option itself is explicitly disabled or not.So we would basically need to check if we are using a Webkit based browser or find other means to determine if we can rely on
option.disabled
in attribute.jsval()
and I don't know if that's acceptable.