Skip to content

Commit 4799d96

Browse files
author
Erin Altenhof-Long
committed
fix(select): revert commit to fix skipping over blank disabled options
An earlier commit caused an error where the first option of a select would be skipped over if it had a blank value. This fix adds a test case to identify this case and shows that reverting the earlier commit causes the behavior to change. In the case of a select with a blank disabled first option, that option should still be selected. Relates to angular#7715
1 parent 6ae6b47 commit 4799d96

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

test/ng/directive/selectSpec.js

+40
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,46 @@ describe('select', function() {
11151115
});
11161116
});
11171117

1118+
describe('disabled blank', function() {
1119+
it('should select disabled blank by default', function() {
1120+
var html = '<select ng-model="someModel" ng-options="c for c in choices">' +
1121+
'<option value="" disabled>Choose One</option>' +
1122+
'</select>';
1123+
scope.$apply(function() {
1124+
scope.choices = ['A', 'B', 'C'];
1125+
});
1126+
1127+
compile(html);
1128+
1129+
var options = element.find('option');
1130+
var optionToSelect = options.eq(0);
1131+
expect(optionToSelect.text()).toBe('Choose One');
1132+
expect(optionToSelect.prop('selected')).toBe(true);
1133+
expect(element.val()).toBe('');
1134+
1135+
dealoc(element);
1136+
});
1137+
1138+
1139+
it('should select disabled blank by default when select is required', function() {
1140+
var html = '<select ng-model="someModel" ng-options="c for c in choices" required>' +
1141+
'<option value="" disabled>Choose One</option>' +
1142+
'</select>';
1143+
scope.$apply(function() {
1144+
scope.choices = ['A', 'B', 'C'];
1145+
});
1146+
1147+
compile(html);
1148+
1149+
var options = element.find('option');
1150+
var optionToSelect = options.eq(0);
1151+
expect(optionToSelect.text()).toBe('Choose One');
1152+
expect(optionToSelect.prop('selected')).toBe(true);
1153+
expect(element.val()).toBe('');
1154+
1155+
dealoc(element);
1156+
});
1157+
});
11181158

11191159
describe('select-many', function() {
11201160

0 commit comments

Comments
 (0)