Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

fix(uiSelectMultiple): Don't call onSelectCallback if limit already reached #1836

Merged
merged 3 commits into from
Nov 3, 2016

Conversation

Jefiozie
Copy link
Contributor

This PR will fix the onSelect problem that was described by #1794 .

@user378230
Copy link
Contributor

user378230 commented Oct 28, 2016

Thanks @Jefiozie

Could we instead move the call to ctrl.onSelectCallback(...) to the $on('uis:select') handlers in uiSelectSingleDirective & uiSelectMultipleDirective?

It seems a little convoluted to have the intermediary ctrl.limitReached boolean floating about.

@Jefiozie
Copy link
Contributor Author

@user378230, Agree will make some changes! Thanks for the feedback.

@user378230
Copy link
Contributor

user378230 commented Oct 28, 2016

@Jefiozie Would you mind also checking for case when limit is not specified? Not easy to tell from code what would happen but I just want to be sure.

Thanks! 😃

@Jefiozie
Copy link
Contributor Author

@user378230 , sure no problem.

@user378230 user378230 changed the title fix: #1794 this will check the limit onselect callback fix(uiSelectMultiple): Don't call onSelectCallback if limit already reached Oct 28, 2016
@Jefiozie
Copy link
Contributor Author

@user378230 Have removed the selectCallBack to the directives and added a test for selectcallback without limit.

@user378230
Copy link
Contributor

user378230 commented Nov 2, 2016

@Jefiozie I think you messed up your commits here. The diff is showing changes other than yours.

Force push to your existing limitOnCallback branch once you've fixed, rather than creating a new PR.

locals[$select.parserResult.itemName] = item;

$timeout(function(){
$select.onSelectCallback(scope, {
Copy link
Contributor

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?

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 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?

Copy link
Contributor

@user378230 user378230 Nov 2, 2016

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...

@@ -1831,7 +1833,7 @@ describe('ui-select tests', function() {
</ui-select>'
);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Check for trailing whitespace in your commits too 👍

clickItem(el, 'Natasha');
$timeout.flush();
expect(el.scope().$select.selected.length).toEqual(2);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to check the value for scope.$model.name?

scope.$item = $item;
scope.$model = $model;
};
var el = createUiSelectMultiple({limit:1,onSelect:'onSelectFn($item, $model)'});
Copy link
Contributor

Choose a reason for hiding this comment

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

minor tidy up of your spacing here.. 😃

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean the bracket?

@user378230
Copy link
Contributor

Just some tiny ones, then it LGTM 👍

@Jefiozie
Copy link
Contributor Author

Jefiozie commented Nov 2, 2016

Fixing it now 😄

@user378230 user378230 merged commit b7ac99a into angular-ui:master Nov 3, 2016
@Jefiozie Jefiozie deleted the limitOnCallBack branch November 3, 2016 15:12
kboga pushed a commit to kboga/ui-select that referenced this pull request Nov 29, 2016
…eached

Previously if a limit was defined for a multiple selection ui-select 
and that limit was reached, the onSelectCallback would still be fired 
even though the item wasn't actually selected. 

This commit moves the firing of the callback to after the select has 
actually taken place to ensure it is only fired on the correct 
occassions.

Fixes angular-ui#1794 
Closes angular-ui#1836
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants