diff options
author | Richard Gibson <richard.gibson@gmail.com> | 2012-09-21 11:53:03 -0400 |
---|---|---|
committer | Dave Methvin <dave.methvin@gmail.com> | 2012-10-03 21:14:08 -0400 |
commit | 425d17de832d281c2577f8d6653030cef95907b5 (patch) | |
tree | b648ebb4300e763d79d29d61e9744c65972d9eba /src/attributes.js | |
parent | da3ff3afe4d8421ae4ad04d6653f04ed6d7768e3 (diff) | |
download | jquery-425d17de832d281c2577f8d6653030cef95907b5.tar.gz jquery-425d17de832d281c2577f8d6653030cef95907b5.zip |
Fix #12583: Don't ignore disabled property of select-one, close gh-932.
Diffstat (limited to 'src/attributes.js')
-rw-r--r-- | src/attributes.js | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/src/attributes.js b/src/attributes.js index cde7e4732..76aed2996 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -225,26 +225,25 @@ jQuery.extend({ }, select: { get: function( elem ) { - var value, i, max, option, - index = elem.selectedIndex, - values = [], + var value, option, options = elem.options, - one = elem.type === "select-one"; - - // Nothing was selected - if ( index < 0 ) { - return null; - } + index = elem.selectedIndex, + one = elem.type === "select-one" || index < 0, + values = one ? null : [], + max = one ? index + 1 : options.length, + i = index < 0 ? + max : + one ? index : 0; // Loop through all the selected options - i = one ? index : 0; - max = one ? index + 1 : options.length; for ( ; i < max; i++ ) { option = options[ i ]; - // Don't return options that are disabled or in a disabled optgroup - if ( option.selected && (jQuery.support.optDisabled ? !option.disabled : option.getAttribute("disabled") === null) && - (!option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" )) ) { + // oldIE doesn't update selected after form reset (#2551) + if ( ( option.selected || i === index ) && + // Don't return options that are disabled or in a disabled optgroup + ( jQuery.support.optDisabled ? !option.disabled : option.getAttribute("disabled") === null ) && + ( !option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" ) ) ) { // Get the specific value for the option value = jQuery( option ).val(); @@ -259,11 +258,6 @@ jQuery.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; }, |