This repository has been archived by the owner on Oct 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(uiSelectMultiple): Don't call onSelectCallback if limit already reached #1836
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1819,6 +1819,8 @@ describe('ui-select tests', function() { | |
if (attrs.lockChoice !== undefined) { matchesAttrsHtml += ' ui-lock-choice="' + attrs.lockChoice + '"'; } | ||
if (attrs.removeSelected !== undefined) { attrsHtml += ' remove-selected="' + attrs.removeSelected + '"'; } | ||
if (attrs.resetSearchInput !== undefined) { attrsHtml += ' reset-search-input="' + attrs.resetSearchInput + '"'; } | ||
if (attrs.limit !== undefined) { attrsHtml += ' limit="' + attrs.limit + '"'; } | ||
if (attrs.onSelect !== undefined) { attrsHtml += ' on-select="' + attrs.onSelect + '"'; } | ||
} | ||
|
||
return compileTemplate( | ||
|
@@ -2764,6 +2766,51 @@ describe('ui-select tests', function() { | |
expect(el.scope().$select.selected.length).toBe(2); | ||
}); | ||
|
||
it('should set only 1 item in the selected items when limit = 1', function () { | ||
var el = createUiSelectMultiple({limit: 1}); | ||
clickItem(el, 'Wladimir'); | ||
clickItem(el, 'Natasha'); | ||
expect(el.scope().$select.selected.length).toEqual(1); | ||
}); | ||
|
||
it('should only have 1 item selected and onSelect function should only be handled once.',function(){ | ||
scope.onSelectFn = function ($item, $model) { | ||
scope.$item = $item; | ||
scope.$model = $model; | ||
}; | ||
var el = createUiSelectMultiple({limit:1,onSelect:'onSelectFn($item, $model)'}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor tidy up of your spacing here.. 😃 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean the bracket? |
||
|
||
expect(scope.$item).toBeFalsy(); | ||
expect(scope.$model).toBeFalsy(); | ||
|
||
clickItem(el, 'Samantha'); | ||
$timeout.flush(); | ||
clickItem(el, 'Natasha'); | ||
$timeout.flush(); | ||
expect(scope.selection.selectedMultiple[0].name).toBe('Samantha'); | ||
expect(scope.$model.name).toEqual('Samantha'); | ||
expect(el.scope().$select.selected.length).toEqual(1); | ||
}); | ||
|
||
it('should only have 2 items selected and onSelect function should be handeld.',function(){ | ||
scope.onSelectFn = function ($item, $model) { | ||
scope.$item = $item; | ||
scope.$model = $model; | ||
}; | ||
var el = createUiSelectMultiple({onSelect:'onSelectFn($item, $model)'}); | ||
|
||
expect(scope.$item).toBeFalsy(); | ||
expect(scope.$model).toBeFalsy(); | ||
|
||
clickItem(el, 'Samantha'); | ||
$timeout.flush(); | ||
expect(scope.$model.name).toEqual('Samantha'); | ||
clickItem(el, 'Natasha'); | ||
$timeout.flush(); | ||
expect(scope.$model.name).toEqual('Natasha'); | ||
expect(el.scope().$select.selected.length).toEqual(2); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to check the value for |
||
|
||
describe('resetSearchInput option multiple', function () { | ||
it('should be true by default', function () { | ||
expect(createUiSelectMultiple().scope().$select.resetSearchInput).toBe(true); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
scope
the correct scope here? Is there a$select.scope
it should be instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did some checking with the unit test if this is the case but then it will fail. Why do you think it should be $select.scope?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My only thought was that it wasn't the same scope as the one in uiSelectController but I guess we don't use a new scope anyway for the uiSelectSingle/Multiple directives so it should be ok...