Created
June 26, 2025 08:16
-
-
Save kieranbarker/b78de4e6fdcdeba6410a5c21dda2a66a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Delete Form</title> | |
</head> | |
<body> | |
<delete-form> | |
<form action="/widgets/1/delete" method="post"> | |
<p> | |
<button type="submit">Delete Widget</button> | |
</p> | |
</form> | |
</delete-form> | |
<script> | |
customElements.define("delete-form", class extends HTMLElement { | |
constructor() { | |
super(); | |
this.form = this.querySelector("form"); | |
if (this.form) { | |
this.form.addEventListener("submit", this); | |
} | |
} | |
handleEvent(event) { | |
event.preventDefault(); | |
if (confirm("Are you sure you want to delete this widget?")) { | |
this.form.submit(); | |
} | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment