From cc768f14943cf4e93888447e7c216b500cff95d9 Mon Sep 17 00:00:00 2001 From: Artem Stepanyuk Date: Fri, 19 Feb 2016 16:29:13 +0300 Subject: [PATCH] Fixed changing of selected checkbox, when it is disabled --- src/bindings/checkboxBinding.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/bindings/checkboxBinding.js b/src/bindings/checkboxBinding.js index 4c7e560..41aa607 100644 --- a/src/bindings/checkboxBinding.js +++ b/src/bindings/checkboxBinding.js @@ -10,17 +10,19 @@ ko.bindingHandlers.checkbox = { value = valueAccessor(), data = $checkbox.val(), isChecked = $checkbox.parent().hasClass('active'); + + if(!$checkbox.prop('disbled')) { + if (ko.unwrap(value) instanceof Array) { + var index = ko.utils.arrayIndexOf(ko.unwrap(value), (data)); - if (ko.unwrap(value) instanceof Array) { - var index = ko.utils.arrayIndexOf(ko.unwrap(value), (data)); - - if (isChecked && (index === -1)) { - value.push(data); - } else if (!isChecked && (index !== -1)) { - value.splice(index, 1); + if (isChecked && (index === -1)) { + value.push(data); + } else if (!isChecked && (index !== -1)) { + value.splice(index, 1); + } + } else { + value(isChecked); } - } else { - value(isChecked); } }, 0); };