0

I am using the Widget factory from jQuery UI into a existing production environment.

This environment uses a binded event called sm2.validateNext which triggers before the page changes. However when trying to bind to this event using _on, it would try to split this event name and delegate it. (Which i believe is correct, bot not the expected functionality for me).

Code (inside the $.widget):

this._on(true, document, {
    "sm2.validateNext": function () { ... },
});

And debugging this code, it gets delegated (not my expected behaviour) (from jquery-ui.widget.js)

var match = event.match( /^(\w+)\s*(.*)$/ ),
eventName = match[1] + instance.eventNamespace,
selector = match[2];
if ( selector ) {
    delegateElement.delegate( selector, eventName, handlerProxy );
} else {
    element.bind( eventName, handlerProxy );
}

Because of the . (dot) it gets a match and selector becomes valid delegating the event. However I need to get binded with its handlerProxy.

Is there a way to avoid get "trapped" into that match? I tried to escape sm2\.validateNext without result.

Note:

$(document).on("sm2.validateNext"...)
Doesnt work for me as I need the instance to be at the widget object.

Thanks for your help!

1 Answer 1

0

Found my solution by using $.proxy

Instead of:

this._on(true, document, {
    "sm2.validateNext": function () { ... },
});

I used:

$(document).on("sm2.validateNext", $.proxy(function () { ... }, this));

And now it works just as I expected.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.