There is the knockout-3.3.0 & jquery-1.11.2 & bootstrap-3 application.
The template with click binding:
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-bind="click: $parent.Submit, text: 'Submit'"></button>
</div>
The viewmodel contains handler:
self.Submit = function (data, event) {
console.log('fired');
/* do some very important staff */
};
If I clicked on Submit button then the event fires once. But if I pressed and held Enter key and clicked on Submit button helding the Enter key being pressed then the event fires from 10 to 20 times.
There is an option to modify the handler like this:
self.isSubmitting = ko.observable(false);
self.Submit = function (data, event) {
if (self.isSubmitting()) {
return;
}
console.log('fired');
self.isSubmitting(true);
/* do some very important staff */
self.isSubmitting(false);
};
But I'd prefer some more general solution instead of modifying each click handler in the application.
So, what do you think? Thank you in advance!
Edit: The problem is fosus on the button after it was clicked. Modifying the event binding is not the option because this behaviour is correct. That's why the solution is to modify the handler to avoid unwanted execusion using isSubmitting boolean variable.