I am using knockout.js with jquery ui button. I built a custom binding on the button which is below. I am changing the text on the click item, but I also have additional click that submits an ajax request. What is the best design pattern to set the text back to the original text once the request is complete. I know I can do it manually or, pass the element being called to the method, but is there a more de-coupled way.
<button type="submit" data-bind="button: { text: 'login', pressed: 'authenticating...' }, click: function() { site.ajaxRequest(); }"></button>
ko.bindingHandlers.button = {
init: function (element, valueAccessor) {
var binding = ko.utils.unwrapObservable(valueAccessor());
$(element).button({ label: binding.text }).click(function () {
$(this).button({ label: binding.pressed });
});
}
};