Bug Tracker

Changeset 5793

Show
Ignore:
Timestamp:
07/23/08 17:00:32 (6 months ago)
Author:
aflesler
Message:

jquery core: closes #2652. val() supports option elements, also simplified the code.

Location:
trunk/jquery
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/jquery/src/core.js

    r5792 r5793  
    363363                var elem = this[0]; 
    364364 
     365                if( jQuery.nodeName( elem, 'option' ) ) 
     366                    return (elem.attributes.value || {}).specified ? elem.value : elem.text; 
     367                 
    365368                // We need to handle select boxes special 
    366369                if ( jQuery.nodeName( elem, "select" ) ) { 
     
    380383                        if ( option.selected ) { 
    381384                            // Get the specifc value for the option 
    382                             value = jQuery.browser.msie && !option.attributes.value.specified ? option.text : option.value; 
     385                            value = jQuery(option).val(); 
    383386 
    384387                            // We don't need an array for one selects 
  • trunk/jquery/test/index.html

    r5708 r5793  
    8787                <option id="option3c" selected="selected" value="2">2</option> 
    8888                <option id="option3d" value="3">3</option> 
     89                <option id="option3e">no value</option> 
    8990            </select> 
    9091             
  • trunk/jquery/test/unit/core.js

    r5792 r5793  
    11431143 
    11441144test("val()", function() { 
    1145     expect(3); 
     1145    expect(8); 
     1146 
    11461147    equals( jQuery("#text1").val(), "Test", "Check for value of input element" ); 
    11471148    // ticket #1714 this caused a JS error in IE 
    11481149    equals( jQuery("#first").val(), "", "Check a paragraph element to see if it has a value" ); 
    11491150    ok( jQuery([]).val() === undefined, "Check an empty jQuery object will return undefined from val" ); 
     1151     
     1152    equals( jQuery('#select2').val(), '3', 'Call val() on a single="single" select' ); 
     1153 
     1154    isSet( jQuery('#select3').val(), ['1', '2'], 'Call val() on a multiple="multiple" select' ); 
     1155 
     1156    equals( jQuery('#option3c').val(), '2', 'Call val() on a option element with value' ); 
     1157     
     1158    equals( jQuery('#option3a').val(), '', 'Call val() on a option element with empty value' ); 
     1159     
     1160    equals( jQuery('#option3e').val(), 'no value', 'Call val() on a option element with no value attribute' ); 
     1161     
    11501162}); 
    11511163 
     
    12361248    isSet( jQuery("p").not(jQuery("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" ); 
    12371249    equals( jQuery("p").not(document.getElementsByTagName("p")).length, 0, "not(Array-like DOM collection)" ); 
    1238     isSet( jQuery("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d" ), "not('complex selector')"); 
     1250    isSet( jQuery("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d", "option3e" ), "not('complex selector')"); 
    12391251 
    12401252    var selects = jQuery("#form select"); 
  • trunk/jquery/test/unit/selector.js

    r5708 r5793  
    196196    t( "Element Preceded By", "p ~ div", ["foo","fx-queue","fx-tests", "moretests"] ); 
    197197    t( "Not", "a.blog:not(.link)", ["mark"] ); 
    198     t( "Not - multiple", "#form option:not(:contains('Nothing'),#option1b,:selected)", ["option1c", "option1d", "option2b", "option2c", "option3d"] ); 
    199     t( "Not - complex", "#form option:not([id^='opt']:gt(0):nth-child(-n+3))", [ "option1a", "option1d", "option2d", "option3d"] ); 
     198    t( "Not - multiple", "#form option:not(:contains('Nothing'),#option1b,:selected)", ["option1c", "option1d", "option2b", "option2c", "option3d", "option3e"] ); 
     199    t( "Not - complex", "#form option:not([id^='opt']:gt(0):nth-child(-n+3))", [ "option1a", "option1d", "option2d", "option3d", "option3e"] ); 
    200200    t( "Not - recursive", "#form option:not(:not(:selected))[id^='option3']", [ "option3b", "option3c"] ); 
    201201