Replies: 2 comments 1 reply
-
I have the same issue when using Superforms in SPA mode with Carbon. |
Beta Was this translation helpful? Give feedback.
-
Hello, this can be achieved by providing a custom handler to <script>
/* import statements here */
let formElement;
const formHandler = () => {
console.log('form submitted');
return async ({ update }) => {
await update();
open = false;
await tick();
notificationWrapper.focus();
};
};
</script>
<Modal
hasForm
on:click:button--primary={() => formElement.requestSubmit()}
on:click:button--secondary={() => (open = false)}
bind:open
modalHeading="Form example"
primaryButtonText="Submit"
secondaryButtonText="Cancel"
<!-- this is `true` by default, we want to prevent submit on 'cancel' -->
shouldSubmitOnEnter={false}
>
<form method="POST" bind:this={formElement} use:enhance={formHandler}>
<TextInput name="name" labelText="Your name" />
</form>
</Modal> Note, submitting the form requires JS at this time. More enhancements will be explored in #310 and #1622. Demo: https://www.sveltelab.dev/z8mq7xsqiklnr8f Note, the demo doesn't include loading indicators, which I recommend adding. |
Beta Was this translation helpful? Give feedback.
-
Any way to submit a form from the Modal component, probably the on:submit event, while using enhance?
Snippets below illustrates my current workaround. Doesn't look nice, but hope it illustrates what I want to achieve (getting rid of the
document.getElementById...
)Beta Was this translation helpful? Give feedback.
All reactions