bitinn
bitinn

Reputation: 9338

Knockout custom click binding, return true to prevent click hijack?

So we all know return true manually will allow default click action on element with a click binding, but what if I have custom binding as following:

ko.bindingHandlers.action = {
    init: function(element, valueAccessor, allBindingsAccessor, context) {
        var options = valueAccessor();
        var params = options.slice(1);

        //wrap it in function, with parameter binding
        var newValueAccessor = function() {
            return function() {
                options[0].apply(context, params);
            };
        };

        ko.bindingHandlers.click.init(element, newValueAccessor, allBindingsAccessor, context);
    }
};

which takes N arguments from a binding:

action: [handle, 'open', $index()]

how does one allow click to go through? return true in handle does not work in this case.

Upvotes: 0

Views: 780

Answers (1)

Michael Best
Michael Best

Reputation: 16688

Your actual click handler is defined here:

        return function() {
            options[0].apply(context, params);
        };

Just change it so it returns the value of the provided sub-handler:

        return function() {
            return options[0].apply(context, params);
        };

Upvotes: 2

Related Questions