Kendo MVVM supports click event (data-bind="enabled: isEnabled, events: { click: onClick }"), like documentation on button demonstrates http://demos.telerik.com/kendo-ui/button/mvvm. Is there a way to prevent click of element while onClick function is executing and when onClick function finishes, element is enabled again.
Upper functionality can be accomplished by first disabling element and at the end of function enabling it again.
<div id="example"> <button data-role="button" data-bind="visible: isVisible, enabled: isEnabled, events: { click: onClick }">Click me</button> </div><script> var viewModel = kendo.observable({ isVisible: true, isEnabled: true, onClick: function() { this.set("isEnabled", false); // disable kendoConsole.log("event :: click"); this.set("isEnabled", true); // enable } }); kendo.bind($("#example"), viewModel);</script>
Basically is there (or will be) a mvvm event that behaves like jQuery .one. This would specially be good when dealing with deffered objects like this:
<html> <head> <title>bla</title> <script src="http://code.jquery.com/jquery-1.11.3.js"></script> <script type="text/javascript"> $(document).ready(function() { $("#sel" ).on("click", function(e) { $(this).attr("disabled", "disabled"); console.log("Clicked ...."); $.when(bla()).then(function(success){ console.log("Executed ok: " + success); }, function(error) { console.log("error"); }); }); function bla() { var def = $.Deferred(); setTimeout(function(){ def.resolve("ok1"); }, 5000); return def.promise(); } }); </script> </head> <body> <button id="sel">Click me</button> </body></html>