Merge pull request #4974 from umbraco/temp8-fix-conditional-sync-of-checkboxlist

Fixing code in sync functionality of checkbox-list
This commit is contained in:
Bjarke Berg
2019-03-22 09:35:31 +01:00
committed by GitHub

View File

@@ -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,
@@ -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
});
}
}