Skip to content

Commit

Permalink
Merge pull request #4974 from umbraco/temp8-fix-conditional-sync-of-c…
Browse files Browse the repository at this point in the history
…heckboxlist

Fixing code in sync functionality of checkbox-list
  • Loading branch information
bergmania authored Mar 22, 2019
2 parents 9a67989 + e16777f commit 99ebe13
Showing 1 changed file with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ angular.module("umbraco").controller("Umbraco.PropertyEditors.CheckboxListContro
}

function updateViewModel(configItems) {

//check if it's already in sync


//get the checked vals from the view model
var selectedVals = _.map(
_.filter($scope.selectedItems,
Expand All @@ -47,22 +45,22 @@ angular.module("umbraco").controller("Umbraco.PropertyEditors.CheckboxListContro
return m.value;
}
);
//get all of the same values between the arrays
var same = _.intersection($scope.model.value, selectedVals);
//if the lengths are the same as the value, then we are in sync, just exit

if (same.length === $scope.model.value.length === selectedVals.length) {

//if the length is zero, then we are in sync, just exit.
if (_.difference($scope.model.value, selectedVals).length === 0) {
return;
}

$scope.selectedItems = [];


var iConfigItem;
for (var i = 0; i < configItems.length; i++) {
var isChecked = _.contains($scope.model.value, configItems[i].value);
iConfigItem = configItems[i];
var isChecked = _.contains($scope.model.value, iConfigItem.value);
$scope.selectedItems.push({
checked: isChecked,
key: configItems[i].id,
val: configItems[i].value
key: iConfigItem.id,
val: iConfigItem.value
});
}
}
Expand Down

0 comments on commit 99ebe13

Please sign in to comment.