diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/forms/umbcheckbox.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/forms/umbcheckbox.directive.js index d44ca36a5a..47381a15c0 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/forms/umbcheckbox.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/forms/umbcheckbox.directive.js @@ -22,38 +22,51 @@ @param {boolean} model Set to true or false to set the checkbox to checked or unchecked. +@param {string} input-id Set the id of the checkbox. @param {string} value Set the value of the checkbox. @param {string} name Set the name of the checkbox. @param {string} text Set the text for the checkbox label. +@param {string} server-validation-field Set the val-server-field of the checkbox. @param {boolean} disabled Set the checkbox to be disabled. @param {boolean} required Set the checkbox to be required. -@param {string} onChange Callback when the value of the input element changes. +@param {string} on-change Callback when the value of the checkbox changed by interaction. **/ (function () { 'use strict'; - - function CheckboxDirective() { - var directive = { - restrict: 'E', - replace: true, - templateUrl: 'views/components/forms/umb-checkbox.html', - scope: { - model: "=", - value: "@", - name: "@", - text: "@", - disabled: "=", - required: "=", - onChange: "&" - } - }; - - return directive; - + + + function UmbCheckboxController($timeout) { + + var vm = this; + + vm.callOnChange = function() { + $timeout(function() { + vm.onChange({model:vm.model, value:vm.value}); + }, 0); + } + } + + + var component = { + templateUrl: 'views/components/forms/umb-checkbox.html', + controller: UmbCheckboxController, + controllerAs: 'vm', + bindings: { + model: "=", + inputId: "@", + value: "@", + name: "@", + text: "@", + serverValidationField: "@", + disabled: "<", + required: "<", + onChange: "&" + } + }; - angular.module('umbraco.directives').directive('umbCheckbox', CheckboxDirective); + angular.module('umbraco.directives').component('umbCheckbox', component); })(); diff --git a/src/Umbraco.Web.UI.Client/src/views/components/forms/umb-checkbox.html b/src/Umbraco.Web.UI.Client/src/views/components/forms/umb-checkbox.html index b11e682da8..d40263c6b6 100644 --- a/src/Umbraco.Web.UI.Client/src/views/components/forms/umb-checkbox.html +++ b/src/Umbraco.Web.UI.Client/src/views/components/forms/umb-checkbox.html @@ -1,16 +1,19 @@ 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 be3d5217f5..3b6c47478e 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 @@ -50,8 +50,8 @@ angular.module("umbraco").controller("Umbraco.PropertyEditors.CheckboxListContro //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) { - return; + if (same.length === $scope.model.value.length === selectedVals.length) { + return; } $scope.selectedItems = []; @@ -66,18 +66,14 @@ angular.module("umbraco").controller("Umbraco.PropertyEditors.CheckboxListContro } } - function changed(item) { + function changed(model, value) { - var index = _.findIndex($scope.model.value, - function (v) { - return v === item.val; - } - ); + var index = $scope.model.value.indexOf(value); - if (item.checked) { + if (model) { //if it doesn't exist in the model, then add it if (index < 0) { - $scope.model.value.push(item.val); + $scope.model.value.push(value); } } else { //if it exists in the model, then remove it diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/checkboxlist/checkboxlist.html b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/checkboxlist/checkboxlist.html index 18089b022a..783b413d5e 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/checkboxlist/checkboxlist.html +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/checkboxlist/checkboxlist.html @@ -1,7 +1,7 @@