Skip to content

Instantly share code, notes, and snippets.

@helabenkhalfallah
Created April 10, 2024 20:03
Show Gist options
  • Select an option

  • Save helabenkhalfallah/a594a826905fdca1d62a2f9c9f3e633e to your computer and use it in GitHub Desktop.

Select an option

Save helabenkhalfallah/a594a826905fdca1d62a2f9c9f3e633e to your computer and use it in GitHub Desktop.
Child Component
<!-- Child.svelte -->
<!-- Script Section -->
<script>
// Import necessary functions from Svelte
import { createEventDispatcher } from 'svelte';
// Create a dispatcher for emitting custom events
const dispatch = createEventDispatcher();
// Define variables to store form data
let username = '';
let email = '';
let password = '';
// Function to handle form submission
const handleSubmit = () => {
// Emit a custom event named 'submit' with form data
dispatch('submit', { username, email, password });
};
</script>
<!-- Form Markup -->
<form on:submit|preventDefault={handleSubmit}>
<!-- Input fields for username, email, and password -->
<label>
Username:
<input type="text" bind:value={username} />
</label>
<label>
Email:
<input type="email" bind:value={email} />
</label>
<label>
Password:
<input type="password" bind:value={password} />
</label>
<!-- Button to submit the form -->
<button type="submit">Submit</button>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment