Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix(ngSelect): Support static options on multi-select drop down #5938

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/ng/directive/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,14 +477,12 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
selected: selected // determine if we should be selected
});
}
if (!multiple) {
if (nullOption || modelValue === null) {
// insert null option if we have a placeholder, or the model is null
optionGroups[''].unshift({id:'', label:'', selected:!selectedSet});
} else if (!selectedSet) {
// option could not be found, we have to insert the undefined item
optionGroups[''].unshift({id:'?', label:'', selected:true});
}
if (nullOption || modelValue === null) {
// insert null option if we have a placeholder, or the model is null
optionGroups[''].unshift({id:'', label:'', selected:!selectedSet});
} else if (!selectedSet) {
// option could not be found, we have to insert the undefined item
optionGroups[''].unshift({id:'?', label:'', selected:true});
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like it's going to fail jshint/tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see any failure on "grunt test"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran grunt jshint & its all green. Am I missing something?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from the diff, it looks like there should be an unexpected closing brace. if not then ignore the comment, but the diff looks like it. Travis is being a bit slow right now, but we'll know soon enough :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just took a second look at this diff and now feels stupid for the above comments

derp

// Now we need to update the list of DOM nodes to match the optionGroups we computed above
Expand Down
34 changes: 34 additions & 0 deletions test/ng/directive/selectSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,40 @@ describe('select', function() {
});


it('should include static option', function() {
createMultiSelect('<option value="">Choose One</option>');

scope.$apply(function() {
scope.values = [{name: 'A'}, {name: 'B'}];
scope.selected = [];
});

expect(element.find('option').length).toEqual(3);
expect(element.find('option')[0].selected).toBeFalsy();
expect(element.find('option')[1].selected).toBeFalsy();
expect(element.find('option')[2].selected).toBeFalsy();

scope.$apply(function() {
scope.selected.push(scope.values[0]);
});

expect(element.find('option').length).toEqual(3);

expect(element.find('option')[0].selected).toBeFalsy();
expect(element.find('option')[1].selected).toBeTruthy();
expect(element.find('option')[2].selected).toBeFalsy();

scope.$apply(function() {
scope.selected.push(scope.values[1]);
});

expect(element.find('option').length).toEqual(3);
expect(element.find('option')[0].selected).toBeFalsy();
expect(element.find('option')[1].selected).toBeTruthy();
expect(element.find('option')[2].selected).toBeTruthy();
});


it('should update model on change', function() {
createMultiSelect();

Expand Down