dbgate/packages/web/src/forms/FormSubmit.svelte
2021-10-14 10:56:11 +02:00

25 lines
608 B
Svelte

<script lang="ts">
import FormStyledButton from '../elements/FormStyledButton.svelte';
import { getFormContext } from './FormProviderCore.svelte';
import { createEventDispatcher } from 'svelte';
export let disabled = false;
const dispatch = createEventDispatcher();
const { submitActionRef } = getFormContext();
const { values } = getFormContext();
function handleClick() {
dispatch('click', $values);
}
submitActionRef.set(() => {
if (!disabled) {
handleClick();
}
});
</script>
<FormStyledButton type="submit" {disabled} on:click={handleClick} {...$$props} />