feat: add support for partials on forms (#1930)
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import { Partial } from "$fresh/runtime.ts";
|
||||
import { defineRoute, Handlers } from "$fresh/server.ts";
|
||||
import { Logger } from "../../islands/Logger.tsx";
|
||||
|
||||
export const handler: Handlers = {
|
||||
POST(req, ctx) {
|
||||
return ctx.render();
|
||||
},
|
||||
};
|
||||
|
||||
export default defineRoute(async (req, ctx) => {
|
||||
let value = "";
|
||||
|
||||
if (req.body !== null) {
|
||||
const data = await req.formData();
|
||||
value += data.has("name") ? data.get("name") + "_foo" : "";
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<form action="/form_post" method="post">
|
||||
<Partial name="slot-1">
|
||||
<p class="status">Default content</p>
|
||||
<p>
|
||||
<input type="text" value={value} name="name" />
|
||||
</p>
|
||||
<Logger name="Form" />
|
||||
<p class="url">{ctx.url.toString()}</p>
|
||||
</Partial>
|
||||
<button type="submit" class="submit">
|
||||
submit
|
||||
</button>
|
||||
</form>
|
||||
<pre id="logs" />
|
||||
</div>
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user