Utility function to invoke a form action
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 2.3k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 156
Description
Describe the problem
Currently form's action can only be used with a HTML <form>
<form method="POST" action="?/load" use:enhance>
<button type="submit">CALL</button>
</form>
It would be nice to be able to call them via a Javascript function...
Describe the proposed solution
We could have a function to call any action.
Exemple :
async function doSomething() {
const data = await callAction('?/load', { /* an object that represents the POST parameters */ })
// ... using data
}
Even better, maybe we could have typed functions automatically generated by Sveltekit :
<script lang="ts">
import { load } from './$actions'; // Generated by sveltekit, based on actions defined on +page.server.ts
async function doSomething() {
const data = await load( { /* an object that represents the POST parameters */ } );
// ... using data (which is correctly typed)
}
</script>
Alternatives considered
No response
Importance
nice to have
Additional Information
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the form action flow using <form action="?/load" use:enhance> and the +page.server.ts actions described in the issue. Determine the API for invoking an action from JavaScript and whether generated $actions functions are in scope; done means the behavior, parameters, return data, and typing are specified clearly enough to implement and test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100