@@ -1592,7 +1592,7 @@ describe('select', function() {
1592
1592
} ) ;
1593
1593
1594
1594
1595
- they ( 'should select a disabled option when the model is set to the matching value' ,
1595
+ they ( 'should select a disabled option with $prop when the model is set to the matching value' ,
1596
1596
[
1597
1597
'ngValue' ,
1598
1598
'interpolatedValue' ,
@@ -1628,20 +1628,23 @@ describe('select', function() {
1628
1628
expect ( optionElements . length ) . toEqual ( 4 ) ;
1629
1629
expect ( optionElements [ 0 ] . value ) . toEqual ( unknownValue ( undefined ) ) ;
1630
1630
1631
- A . disabled = true ;
1631
+ B . disabled = true ;
1632
1632
scope . $digest ( ) ;
1633
1633
1634
1634
var optionElements = element . find ( 'option' ) ;
1635
1635
expect ( optionElements . length ) . toEqual ( 4 ) ;
1636
1636
expect ( optionElements [ 0 ] . value ) . toEqual ( unknownValue ( undefined ) ) ;
1637
1637
1638
- scope . obj . value = 'A ' ;
1638
+ scope . obj . value = 'B ' ;
1639
1639
scope . $digest ( ) ;
1640
1640
1641
1641
optionElements = element . find ( 'option' ) ;
1642
1642
expect ( optionElements . length ) . toEqual ( 3 ) ;
1643
- expect ( scope . obj . value ) . toBe ( 'A' ) ;
1644
- expect ( element . val ( ) ) . toBe ( prop === 'ngValue' ? 'string:A' : 'A' ) ;
1643
+ expect ( scope . obj . value ) . toBe ( 'B' ) ;
1644
+ // jQuery returns null for val() when the option is disabled, see
1645
+ // https://bugs.jquery.com/ticket/13097
1646
+ expect ( element [ 0 ] . value ) . toBe ( prop === 'ngValue' ? 'string:B' : 'B' ) ;
1647
+ expect ( optionElements . eq ( 1 ) . prop ( 'selected' ) ) . toBe ( true ) ;
1645
1648
} ) ;
1646
1649
1647
1650
@@ -1931,7 +1934,7 @@ describe('select', function() {
1931
1934
1932
1935
} ) ;
1933
1936
1934
- they ( 'should set the model to null when the currently selected option with $prop is disabled' ,
1937
+ they ( 'should set the model to null when the currently selected option with $prop becomes disabled' ,
1935
1938
[
1936
1939
'ngValue' ,
1937
1940
'interpolatedValue' ,
@@ -1991,6 +1994,69 @@ describe('select', function() {
1991
1994
} ) ;
1992
1995
1993
1996
1997
+ they ( 'should select disabled options with $prop when the model is set to matching values' ,
1998
+ [
1999
+ 'ngValue' ,
2000
+ 'interpolatedValue' ,
2001
+ 'interpolatedText'
2002
+ ] , function ( prop ) {
2003
+
2004
+ var A = { name : 'A' } , B = { name : 'B' } , C = { name : 'C' } , D = { name : 'D' } ;
2005
+
2006
+ scope . options = [ A , B , C , D ] ;
2007
+ scope . obj = { } ;
2008
+
2009
+ var optionString = '' ;
2010
+
2011
+ switch ( prop ) {
2012
+ case 'ngValue' :
2013
+ optionString = '<option ng-repeat="option in options" ng-disabled="option.disabled" ng-value="option">{{$index}}</option>' ;
2014
+ break ;
2015
+ case 'interpolatedValue' :
2016
+ optionString = '<option ng-repeat="option in options" ng-disabled="option.disabled" value="{{option.name}}">{{$index}}</option>' ;
2017
+ break ;
2018
+ case 'interpolatedText' :
2019
+ optionString = '<option ng-repeat="option in options" ng-disabled="option.disabled">{{option.name}}</option>' ;
2020
+ break ;
2021
+ }
2022
+
2023
+ compile (
2024
+ '<select ng-model="obj.value" multiple>' +
2025
+ optionString +
2026
+ '</select>'
2027
+ ) ;
2028
+
2029
+ var optionElements = element . find ( 'option' ) ;
2030
+ expect ( optionElements . length ) . toEqual ( 4 ) ;
2031
+ expect ( element [ 0 ] . value ) . toBe ( '' ) ;
2032
+
2033
+ A . disabled = true ;
2034
+ D . disabled = true ;
2035
+ scope . $digest ( ) ;
2036
+
2037
+ var optionElements = element . find ( 'option' ) ;
2038
+ expect ( optionElements . length ) . toEqual ( 4 ) ;
2039
+ expect ( element [ 0 ] . value ) . toBe ( '' ) ;
2040
+
2041
+ scope . obj . value = prop === 'ngValue' ? [ A , C , D ] : [ 'A' , 'C' , 'D' ] ;
2042
+ scope . $digest ( ) ;
2043
+
2044
+ optionElements = element . find ( 'option' ) ;
2045
+ expect ( optionElements . length ) . toEqual ( 4 ) ;
2046
+ expect ( scope . obj . value ) . toEqual ( prop === 'ngValue' ?
2047
+ [
2048
+ { name : 'A' , $$hashKey : 'object:4' , disabled : true } ,
2049
+ { name : 'C' , $$hashKey : 'object:6' } ,
2050
+ { name : 'D' , $$hashKey : 'object:7' , disabled : true }
2051
+ ] :
2052
+ [ 'A' , 'C' , 'D' ]
2053
+ ) ;
2054
+
2055
+ expect ( optionElements . eq ( 0 ) . prop ( 'selected' ) ) . toBe ( true ) ;
2056
+ expect ( optionElements . eq ( 2 ) . prop ( 'selected' ) ) . toBe ( true ) ;
2057
+ expect ( optionElements . eq ( 3 ) . prop ( 'selected' ) ) . toBe ( true ) ;
2058
+ } ) ;
2059
+
1994
2060
they ( 'should select a newly added option with $prop when it matches the current model' ,
1995
2061
[
1996
2062
'ngValue' ,
0 commit comments