]> source.dussan.org Git - jquery.git/commitdiff
Attrs: Force reflow in select value setter 1485/head
authorOleg <markelog@gmail.com>
Tue, 14 Jan 2014 22:26:56 +0000 (02:26 +0400)
committerOleg <markelog@gmail.com>
Thu, 16 Jan 2014 00:56:32 +0000 (04:56 +0400)
When new option element is added to select box we need to force reflow
of newly added node in order to workaround delay of initialization props.

try...catch statment is required for bug isolation

Fixes #2252

src/attributes/val.js

index 16296a6316ccd9cbf8203a4e7a51da937e7cfc9a..b01eebff71e881925db663def90d7b0b8fbc11ab 100644 (file)
@@ -118,21 +118,37 @@ jQuery.extend({
                        set: function( elem, value ) {
                                var optionSet, option,
                                        options = elem.options,
-                                       values = jQuery.makeArray( value ),
                                        i = options.length;
 
                                while ( i-- ) {
                                        option = options[ i ];
-                                       if ( (option.selected = jQuery.inArray( jQuery(option).val(), values ) >= 0) ) {
-                                               optionSet = true;
+
+                                       if ( jQuery.valHooks.option.get( option ) === value ) {
+
+                                               // Support: IE6
+                                               // When new option element is added to select box we need to
+                                               // force reflow of newly added node in order to workaround delay
+                                               // of initialization properties
+                                               try {
+                                                       option.selected = optionSet = true;
+
+                                               } catch ( _ ) {
+
+                                                       // Will be executed only in IE6
+                                                       option.scrollHeight;
+                                               }
+
+                                       } else {
+                                               option.selected = false;
                                        }
                                }
 
-                               // force browsers to behave consistently when non-matching value is set
+                               // Force browsers to behave consistently when non-matching value is set
                                if ( !optionSet ) {
                                        elem.selectedIndex = -1;
                                }
-                               return values;
+
+                               return options;
                        }
                }
        }