Skip to content

Commit 661bd7a

Browse files
committed
Form submits in place.
1 parent 02f6f0d commit 661bd7a

4 files changed

Lines changed: 40 additions & 2 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
name: preview-local
3+
description: Use playwright mcp to view local docs
4+
---
5+
# Preview local
6+
7+
# When to use
8+
* When you need to diagnose or confirm issues with docs
9+
10+
## Instructions
11+
12+
* The dev server should already be running.
13+
* Use the playwright mcp server.
14+
* Go to the [docs homepage](http://localhost:8000/#welcome). If the page does not load because the dev server is not running, stop.
15+
* browse as necessary
16+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
document.addEventListener("submit", (event) => {
2+
const form = event.target.closest("[data-feedback-form]");
3+
if (!form) return;
4+
5+
event.preventDefault();
6+
7+
if (!form.reportValidity()) return;
8+
9+
const container = form.closest("[data-feedback-form-container]");
10+
if (!container) return;
11+
12+
const data = Object.fromEntries(new FormData(form));
13+
fetch(form.action, {
14+
method: form.method || "POST",
15+
headers: { "Content-Type": "application/json" },
16+
body: JSON.stringify(data),
17+
}).catch(() => {});
18+
19+
container.innerHTML = "<p>Thank you for your feedback!</p>";
20+
});

docs/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ Wallstreet.io has everything a trader could need to trade wisely:
2121

2222
## Report an issue
2323

24-
<form action="https://example.com/feedback" method="POST">
24+
<div data-feedback-form-container>
25+
<form action="https://example.com/feedback" method="POST" data-feedback-form>
2526
<p>
2627
<label for="page-url">Page URL</label><br>
2728
<input type="url" id="page-url" name="url" class="md-input md-input--stretch" required >
@@ -36,4 +37,5 @@ Wallstreet.io has everything a trader could need to trade wisely:
3637
</p>
3738
<button type="submit" class="md-button md-button--primary">Submit</button>
3839
</form>
40+
</div>
3941

zensical.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ extra_css = ["assets/stylesheets/extra.css"]
109109
# The path provided should be relative to the "docs_dir".
110110
#
111111
# Read more: https://zensical.org/docs/customization/#additional-javascript
112-
#extra_javascript = ["javascripts/extra.js"]
112+
extra_javascript = ["assets/javascript/feedback-form.js"]
113113

114114
# ----------------------------------------------------------------------------
115115
# Section for configuring theme options

0 commit comments

Comments
 (0)