-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Model field reference edit pre poulated selections #217
base: master
Are you sure you want to change the base?
Model field reference edit pre poulated selections #217
Conversation
|
||
function removeSelectedFromList(selected, list, id) { | ||
var filteredList = _.reject(list, function(o) { | ||
for (var i = 0; i < selected.length; i++) { |
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.
Maybe we can use _.find() here instead?
@@ -140,7 +158,7 @@ angular.module('dashboard.directives.ModelFieldReference', [ | |||
if (scope.options.api) apiPath = replaceSessionVariables(scope.options.api); | |||
GeneralModelService.list(apiPath, params, {preventCancel: true}).then(function(response) { | |||
if (!response) return; //in case http request was cancelled by newer request | |||
scope.list = response; | |||
scope.list = scope.selected.items ? removeSelectedFromList(scope.selected.items, response, scope.options.key) : response; |
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.
Do we need the branch? Can we just always do:
scope.list = removeSelectedFromlist()
?
…ttps://github.com/stephguac/isbx-loopback-cms into model-field-reference-edit-pre-poulated-selections
@@ -68,6 +68,22 @@ angular.module('dashboard.directives.ModelFieldReference', [ | |||
if (!scope.data) scope.selected = {}; | |||
}); | |||
|
|||
scope.$watch('selected.items', function() { // watch selected.items to ensure previously selected items are accounted for. | |||
if (scope.selected && scope.selected.items && scope.selected.items.length) { |
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.
We shouldn't check length here, otherwise removing the last selected item will not refreshChoices, etc.
@tma-isbx