1 ko.bindingHandlers['submit'] = {
2 'init': function (element, valueAccessor, allBindings, viewModel, bindingContext) {
3 if (typeof valueAccessor() != "function")
4 throw new Error("The value for a submit binding must be a function");
5 ko.utils.registerEventHandler(element, "submit", function (event) {
6 var handlerReturnValue;
7 var value = valueAccessor();
8 try { handlerReturnValue = value.call(bindingContext['$data'], element); }
10 if (handlerReturnValue !== true) { // Normally we want to prevent default action. Developer can override this be explicitly returning true.
11 if (event.preventDefault)
12 event.preventDefault();
14 event.returnValue = false;