public
Description: Updated hourly from the jQuery SVN repo
Homepage: http://jquery.com
Clone URL: git://github.com/JackDanger/jquery.git
jquery core: closes #2652. val() supports option elements, also simplified 
the code.

git-svn-id: http://jqueryjs.googlecode.com/svn/trunk@5793 
c715fcbe-d12f-0410-84c4-316a508785bb
aflesler (author)
Wed Jul 23 10:00:32 -0700 2008
commit  ba5f215e61e6078da426bdd3e5519d82994120ea
tree    1427fa38b74eb2244a5fc7547495c596840c9aee
parent  0083461eb20d4d5858a866c203fb4f12f927360b
...
362
363
364
 
 
 
365
366
367
...
379
380
381
382
 
383
384
385
...
362
363
364
365
366
367
368
369
370
...
382
383
384
 
385
386
387
388
0
@@ -362,6 +362,9 @@ jQuery.fn = jQuery.prototype = {
0
       if ( this.length ) {
0
         var elem = this[0];
0
 
0
+ if( jQuery.nodeName( elem, 'option' ) )
0
+ return (elem.attributes.value || {}).specified ? elem.value : elem.text;
0
+
0
         // We need to handle select boxes special
0
         if ( jQuery.nodeName( elem, "select" ) ) {
0
           var index = elem.selectedIndex,
0
@@ -379,7 +382,7 @@ jQuery.fn = jQuery.prototype = {
0
 
0
             if ( option.selected ) {
0
               // Get the specifc value for the option
0
- value = jQuery.browser.msie && !option.attributes.value.specified ? option.text : option.value;
0
+ value = jQuery(option).val();
0
 
0
               // We don't need an array for one selects
0
               if ( one )
...
86
87
88
 
89
90
91
...
86
87
88
89
90
91
92
0
@@ -86,6 +86,7 @@
0
         <option id="option3b" selected="selected" value="1">1</option>
0
         <option id="option3c" selected="selected" value="2">2</option>
0
         <option id="option3d" value="3">3</option>
0
+ <option id="option3e">no value</option>
0
       </select>
0
       
0
       <object id="object1" codebase="stupid">
...
1142
1143
1144
1145
 
 
1146
1147
1148
1149
 
 
 
 
 
 
 
 
 
 
 
1150
1151
1152
...
1235
1236
1237
1238
 
1239
1240
1241
...
1142
1143
1144
 
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
...
1247
1248
1249
 
1250
1251
1252
1253
0
@@ -1142,11 +1142,23 @@ test("jQuery.extend(Object, Object)", function() {
0
 });
0
 
0
 test("val()", function() {
0
- expect(3);
0
+ expect(8);
0
+
0
   equals( jQuery("#text1").val(), "Test", "Check for value of input element" );
0
   // ticket #1714 this caused a JS error in IE
0
   equals( jQuery("#first").val(), "", "Check a paragraph element to see if it has a value" );
0
   ok( jQuery([]).val() === undefined, "Check an empty jQuery object will return undefined from val" );
0
+
0
+ equals( jQuery('#select2').val(), '3', 'Call val() on a single="single" select' );
0
+
0
+ isSet( jQuery('#select3').val(), ['1', '2'], 'Call val() on a multiple="multiple" select' );
0
+
0
+ equals( jQuery('#option3c').val(), '2', 'Call val() on a option element with value' );
0
+
0
+ equals( jQuery('#option3a').val(), '', 'Call val() on a option element with empty value' );
0
+
0
+ equals( jQuery('#option3e').val(), 'no value', 'Call val() on a option element with no value attribute' );
0
+
0
 });
0
 
0
 test("val(String/Number)", function() {
0
@@ -1235,7 +1247,7 @@ test("not()", function() {
0
   isSet( jQuery("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" );
0
   isSet( jQuery("p").not(jQuery("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" );
0
   equals( jQuery("p").not(document.getElementsByTagName("p")).length, 0, "not(Array-like DOM collection)" );
0
- isSet( jQuery("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d" ), "not('complex selector')");
0
+ isSet( jQuery("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d", "option3e" ), "not('complex selector')");
0
 
0
   var selects = jQuery("#form select");
0
   isSet( selects.not( selects[1] ), q("select1", "select3"), "filter out DOM element");
...
195
196
197
198
199
 
 
200
201
202
...
195
196
197
 
 
198
199
200
201
202
0
@@ -195,8 +195,8 @@ test("pseudo (:) selectors", function() {
0
   t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
0
   t( "Element Preceded By", "p ~ div", ["foo","fx-queue","fx-tests", "moretests"] );
0
   t( "Not", "a.blog:not(.link)", ["mark"] );
0
- t( "Not - multiple", "#form option:not(:contains('Nothing'),#option1b,:selected)", ["option1c", "option1d", "option2b", "option2c", "option3d"] );
0
- t( "Not - complex", "#form option:not([id^='opt']:gt(0):nth-child(-n+3))", [ "option1a", "option1d", "option2d", "option3d"] );
0
+ t( "Not - multiple", "#form option:not(:contains('Nothing'),#option1b,:selected)", ["option1c", "option1d", "option2b", "option2c", "option3d", "option3e"] );
0
+ t( "Not - complex", "#form option:not([id^='opt']:gt(0):nth-child(-n+3))", [ "option1a", "option1d", "option2d", "option3d", "option3e"] );
0
   t( "Not - recursive", "#form option:not(:not(:selected))[id^='option3']", [ "option3b", "option3c"] );
0
   
0
   t( "nth Element", "p:nth(1)", ["ap"] );

Comments

    No one has commented yet.