Skip to content
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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

stephguac
Copy link

@stephguac stephguac commented Aug 22, 2017


function removeSelectedFromList(selected, list, id) {
var filteredList = _.reject(list, function(o) {
for (var i = 0; i < selected.length; i++) {
Copy link
Contributor

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;
Copy link
Contributor

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

@@ -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) {
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants