Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show form submission success messages #67

Merged
merged 2 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<h1>auto-check-element</h1>
<h2>Simple form</h2>
<p>Input 422 for an error response.</p>
<p id="success1" class="success" hidden>Your submission was successful</p>
<form>
<p>All fields marked with * are required</p>

Expand All @@ -21,11 +22,12 @@ <h2>Simple form</h2>
<input id="simple-field" autofocus name="foo" required />
<code class="state"></code>
</auto-check>
<button>submit</button>
<button value="1" name="form">submit</button>
</form>

<h2>Form that has custom validity messages</h2>
<p>Input 422 for an error response.</p>
<p id="success2" class="success" hidden>Your submission was successful</p>
<form id="custom">
<p>All fields marked with * are required</p>

Expand All @@ -34,11 +36,13 @@ <h2>Form that has custom validity messages</h2>
<input id="custom-field" autofocus class="json" name="foo" required />
<code class="state"></code>
</auto-check>
<button>submit</button>
<button value="2" name="form">submit</button>
</form>
</main>

<script>
let successN = new URL(window.location).searchParams.get('form')
if (successN) document.getElementById(`success${successN}`).hidden = false
let focusedInput
const nativeFetch = window.fetch
const fakeFetch = function (_, options) {
Expand Down
2 changes: 1 addition & 1 deletion src/auto-check-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AutoCheckValidationEvent extends AutoCheckEvent {
super(phase)
}

setValidity(message: string) {
setValidity = (message: string) => {
this.message = message
}
}
Expand Down