Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom binding with click and clickBubble does not work? #1377

Closed
julienaubert opened this issue Apr 1, 2014 · 1 comment
Closed

custom binding with click and clickBubble does not work? #1377

julienaubert opened this issue Apr 1, 2014 · 1 comment
Milestone

Comments

@julienaubert
Copy link

I have a few cases where I have <a> which I want to be regular clicks, so I wrote a custom binder.

There seems to be an inconsistency how click vs event works though. My first attempt did not work:

ko.bindingHandlers.domClick = {
    init: function(element, valueAccessor, allBindings, deprecated, bindingContext) {
        ko.applyBindingAccessorsToNode(element, {
            click: function() {return true;},
            clickBubble: function() {return false;}
        }, bindingContext);
    }
}

The 'clickBubble' is not available in the allBindings() in the event.init for some reason (and so it assumes bubble is false). If I instead use 'event', then it works:

ko.bindingHandlers.domClick = {
    init: function(element, valueAccessor, allBindings, deprecated, bindingContext) {
        ko.applyBindingAccessorsToNode(element, {
            event: function() {return { 'click': function() {return true;}}},
            clickBubble: function() {return false;}
        }, bindingContext);
    }
}

I am not sure as to why, seems odd?

@mbest
Copy link
Member

mbest commented Dec 2, 2016

The first example needs to change to this:

ko.bindingHandlers.domClick = {
    init: function(element, valueAccessor, allBindings, deprecated, bindingContext) {
        ko.applyBindingAccessorsToNode(element, {
            click: function() {return function() {return true;}; },
            clickBubble: function() {return false;}
        }, bindingContext);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants