Reputation: 643
I have a list item. When user clicks on "X", for any list item, I need to show a confirmation box for delete which says Are you sure you want to delete this item? along with Yes/No buttons.
If user clicks on Yes, the item should be deleted. My code for deletion works perfectly fine. I am just not sure how to show a window.confirm in the html part. Here's my code:
<ul data-bind="foreach: activeList">
<li data-bind="click: function () { $root.delete('Item', $data); }">
<a data-bind="click: function () { $root.DeleteFile('Item', $data); }">
<img src="../../DeleteCross.png" />
</a>
</li>
</ul>
Please suggest.
Upvotes: 1
Views: 1994
Reputation: 19882
you can not do this on html part. You need to display this on javascript part.
<li data-bind="click:$root.delete('Item', $data)">
<a data-bind="click:$root.DeleteFile('Item', $data)">
<img src="../../DeleteCross.png" />
</a>
</li>
In your viewmodel create function like this
self.delete = function() {
var confirm_delete = confirm('Are you sure you want to delete this?');
if (confirm_delete) {
// deletion code goes here
}
}
Upvotes: 3