I can't figure out how to create a knockout click binding that doesn't execute the valueAccessor unless a javascript confirm dialog returns true.
It's probably look something like this:
<a data-bind=confirmClick: { message: 'Are you sure?', click: someMethod }>Confirmable link</a>
Internally, the confirmClick binding would do something like:
if (confirm(message)) {
click();
}
I know I could get around having to do this by putting the confirm(...)
code in my
viewModel, but that doesn't seem like the appropriate place to put that kind of code. I could probably also go as far as to do this kind of confirm dialog with jQueryUI or Bootstrap, but I want something I can just drop into any project.
I've scoured the internets with no luck.. I even looked at the source code for knockout's click event (https://github.com/knockout/knockout/blob/master/src/binding/defaultBindings/event.js), but it doesn't look friendly at all...
Any help at all would be greatly appreciated!