From 6d88726479b17338dcc2f3860a4b423ade7fff7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Wed, 13 Mar 2019 11:46:33 +0100 Subject: [PATCH] Fixing code in sync functionality of checkbox-list --- .../checkboxlist/checkboxlist.controller.js | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/checkboxlist/checkboxlist.controller.js b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/checkboxlist/checkboxlist.controller.js index 5ba9746c6e..43e50dc392 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/checkboxlist/checkboxlist.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/checkboxlist/checkboxlist.controller.js @@ -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,23 @@ 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) { + debugger; 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 }); } }