I have a basic SpringBoot app. using Spring Initializer, embedded Tomcat, Thymeleaf template engine, and package as an executable JAR file. I want to use a JQuery dialog as Confirm dialog (prompting the user to confirm that they are sure about deleting a record) in a page where I already have a Datatable; but it seems that when I combine both nothing works.
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<!--
http://www.simplecodestuffs.com/how-to-use-jquery-dialog-as-confirm-dialog/
-->
<head>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.2/themes/redmond/jquery-ui.css" />
<script src="https://code.jquery.com/jquery-1.11.2.js"></script>
<script src="https://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<!-- User Defined Js file -->
</head>
<body>
<form method="post" action="delete.html">
<input type="submit" class="button" id="Delete" name="Delete" value="Delete" />
</form>
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</tfoot>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>System Architect</td>
<td>Edinburgh</td>
<td>61</td>
<td>2011/04/25</td>
<td>$320,800</td>
</tr>
</tbody>
</table>
</body>
<script>
$(document).ready(function(){
$('#example').DataTable();
$('#Delete').click(function(event) {
event.preventDefault();
var currentForm = $(this).closest('form');
/** Create div element for delete confirmation dialog*/
var dynamicDialog = $('<div id="conformBox">'+
'<span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;">'+
'</span>Are you sure to delete the item?</div>');
dynamicDialog.dialog({
title : "Are you sure?",
closeOnEscape: true,
modal : true,
buttons :
[{
text : "Yes",
click : function() {
$(this).dialog("close");
currentForm.submit();
}
},
{
text : "No",
click : function() {
$(this).dialog("close");
}
}]
});
return false;
});
});
</script>
</html>
This is what I see from the code abode in the browser
and when I click in the button:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sun May 14 07:13:59 CEST 2017
There was an unexpected error (type=Not Found, status=404).
No message available
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<!--
http://www.simplecodestuffs.com/how-to-use-jquery-dialog-as-confirm-dialog/
-->
<head>
<script src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.15/css/jquery.dataTables.min.css" />
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.2/themes/redmond/jquery-ui.css" />
<script src="https://code.jquery.com/jquery-1.11.2.js"></script>
<script src="https://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<!-- User Defined Js file -->
</head>
<body>
<form method="post" action="delete.html">
<input type="submit" class="button" id="Delete" name="Delete" value="Delete" />
</form>
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</tfoot>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>System Architect</td>
<td>Edinburgh</td>
<td>61</td>
<td>2011/04/25</td>
<td>$320,800</td>
</tr>
</tbody>
</table>
</body>
<script>
$(document).ready(function(){
$('#example').DataTable();
$('#Delete').click(function(event) {
event.preventDefault();
var currentForm = $(this).closest('form');
/** Create div element for delete confirmation dialog*/
var dynamicDialog = $('<div id="conformBox">'+
'<span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;">'+
'</span>Are you sure to delete the item?</div>');
dynamicDialog.dialog({
title : "Are you sure?",
closeOnEscape: true,
modal : true,
buttons :
[{
text : "Yes",
click : function() {
$(this).dialog("close");
currentForm.submit();
}
},
{
text : "No",
click : function() {
$(this).dialog("close");
}
}]
});
return false;
});
});
</script>
</html>