Skip to content

Commit

Permalink
Add preventDefault() to Form 4
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlbyk committed Jul 30, 2023
1 parent 93e4f63 commit 89a1e13
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Pages/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,21 @@
</form>
</fieldset>

@section scripts {
<script>
document.addEventListener('DOMContentLoaded', function () {
console.log('Listening to Form 4')
document.getElementById('prevent-default').addEventListener('submit', function (e) {
e.preventDefault();
let data = new FormData(e.currentTarget);
alert(new URLSearchParams(data));
});
});
</script>
}
<fieldset>
<legend>Form 4</legend>
<form method="post">
<legend>Form 4 (<code>preventDefault()</code>)</legend>
<form method="post" id="prevent-default">
<div class="form-field">
<label asp-for="Input.SomeRequiredField"></label>
<input asp-for="Input.SomeRequiredField"/>
Expand Down
1 change: 1 addition & 0 deletions Pages/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
const service = new aspnetValidation.ValidationService(console);
service.bootstrap(console.log);
</script>
@RenderSection("scripts", required: false)

</body>
</html>

0 comments on commit 89a1e13

Please sign in to comment.