problems after upgrade to knockout 3.1

81 views Asked by At

When i want deal with radio button in knockout 2.0 I used the below code but now i upgrade to knockout 3.1 and this below code throw exception say that update is not a function.

ko.bindingHandlers.radioOnOffBoolean =
{
    init: function (element, valueAccessor, allBindingsAccessor) {
        var value = valueAccessor();
        var newValueAccessor = function () {
            return ko.dependentObservable({
                read: value,
                write: function (newValue) {
                    value(newValue === "On");
                }
            });
        };

        ko.bindingHandlers.checked.init(element, newValueAccessor, allBindingsAccessor);
    },
    update: function (element, valueAccessor) {
        var value = ko.utils.unwrapObservable(valueAccessor());
        var newValueAccessor = function () {
            return value ? "On" : "Off";
        };
        ko.bindingHandlers.checked.update(element, newValueAccessor);

    }
};
1

There are 1 answers

0
Ivan Rodriguez On

Knockout v3 now checks for strict equality when comparing model values and element values for the checked binding.

var isCheckedValue = ko.observable(true);

<input type="radio" name="example" data-bind="checked: isCheckedValue, checkedValue: true" />