JSFiddle - React, Tailwind, and code Playground
by notadam
HTML
<div id="app">
<div data-bind="text: name"></div>
<form data-bind="submitEvent: submit">
<button type="submit">
Submit
</button>
</form>
</div>
JavaScript
ko.bindingHandlers.submitEvent = {
init: function(element, valueAccessor) {
var value = valueAccessor()
var valueUnwrapped = ko.unwrap(value)
element.addEventListener("submit", function(event) {
valueUnwrapped(event, element)
})
}
}
var vm = {
name: ko.observable('foo'),
submit: function(event, el) {
event.preventDefault()
console.log(event)
}
}
ko.applyBindings(vm)