Svelte 5 Runes: Reactive Form with Real-time Validation
Prompt
Create an interactive form using Svelte 5 Runes with real-time validation feedback. The form should demonstrate $state, $derived, and $effect runes with visual validation states that update as the user types.
CODE PREVIEW
AI rewrites this code based on your instructions. Preview is free; copy & download unlocked for ¥100.
AIとの対話に追加する一言
プロンプトと一緒にコピーして、AIがより正確に意図を汲み取れるようにします
このコードをそのまま使いたいので、CDNリンクも含めた完全なHTMLファイルとして出力してください。
初心者なので、各行にコメントを追加して、何をしているか説明してください。
このコードをWordPressのテーマに組み込む方法も教えてください。
動作確認済みのコードをお願いします。エラーが出る場合の対処法も含めて。
This interactive form demonstrates Svelte 5's new Runes system with real-time validation. The form uses three core runes: $state for reactive variables, $derived for computed values, and $effect for side effects.
The form validates user input as they type, providing immediate visual feedback through color-coded borders and validation messages. Each field has specific validation rules:
- Name: Must be at least 2 characters long
- Email: Must match a valid email pattern
- Password: Must be at least 8 characters with one uppercase letter and one number
The submit button is dynamically enabled/disabled based on the overall form validity, which is computed using the $derived rune. When the form is successfully submitted, a success message appears and the form resets after 3 seconds using the $effect rune for cleanup.
This example showcases how Svelte 5's Runes provide a more explicit and flexible reactivity system compared to Svelte 4's reactive statements and stores.
Was this prompt helpful?
Comments
Comments appear after moderation
この記事が役に立ったら投げ銭で応援
Apple Pay / Google Pay / カード (Visa/Mastercard/JCB/Amex) / Link / Alipay / WeChat Pay 対応 · Stripeで安全に決済
開発者が選ぶ最強ツール集
運営者が毎日使っているツール・ガジェット 6選