Best way for getting the response without devalue #13307
-
The +page.server.js has something like this:
Then on front-end:
The buttons will trigger an async function to call the API like so The reason I don't use form with form data and progresive enhance is that there are many buttons, I think it doesn't make sense to have many forms to trigger the API?
Instead of using forms which I think is not suitable:
If so, do the deserialize way above is correct and best way to do it? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
What are you trying to do here? Forms can have any number of buttons and pages can have any number of forms if necessary. Though if you do everything via JS, the form is guaranteed to not work, if the JS fails to load. That should always be a consideration when circumventing regular form submission logic. |
Beta Was this translation helpful? Give feedback.
Yes, form actions are designed to be used with forms and by default return their data to the special
form
property. So if the performed action is not intended to be used in a form at all, it does not make as much sense to use a form action.You can of course still use a form action and
deserialize
its data for convenience (e.g. this supports more data types and you can have many different form actions on a single page), the assumed intent might just be a bit off, then.