Skip to content

Commit

Permalink
manage: confirm dialog for recipe delete
Browse files Browse the repository at this point in the history
  • Loading branch information
kassner committed Oct 2, 2023
1 parent 2422c04 commit 87acac5
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/main/resources/templates/recipe/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,24 @@ <h1 class="flex-grow">Manage recipes</h1>
<td th:text="${recipe.getName()}"></td>
<td class="actions">
<a class="btn-edit" th:href="@{/manage/recipe/{id}/edit(id=${recipe.getId()})}">Edit</a>
<form th:action="@{/manage/recipe/{id}/delete(id=${recipe.getId()})}" method="POST">
<form th:action="@{/manage/recipe/{id}/delete(id=${recipe.getId()})}" method="POST" th:data-recipe-name="${recipe.getName()}">
<button class="btn-delete w-full">Delete</button>
</form>
</td>
</tr>
</tbody>
</table>
<script type="text/javascript">
document.querySelectorAll('form').forEach((form) => {
form.addEventListener('submit', (e) => {
const recipe = e.target.attributes.getNamedItem('data-recipe-name').value;
const message = `Are you sure you want to delete "${recipe}"?`;
if (!confirm(message)) {
e.preventDefault();
}
});
});
</script>
</main>
</body>
</html>

0 comments on commit 87acac5

Please sign in to comment.