AIGPAIGP

Svelte 5 Runes: Reactive Form with Real-Time Validation

CODE PREVIEW

エディタを読み込み中…
P

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.

このインタラクティブフォームは、リアルタイムバリデーション付きでSvelte 5の新しいRunesシステムを実演しています。フォームは3つのコアルーンを使用しています:リアクティブ変数のための$state、計算値のための$derived、副作用のための$effectです。

フォームはユーザーが入力する際にリアルタイムでバリデーションを行い、色分けされたボーダーとバリデーションメッセージを通じて即時の視覚的フィードバックを提供します。各フィールドには特定のバリデーションルールがあります:

  • 名前: 2文字以上である必要があります
  • メール: 有効なメールパターンに一致する必要があります
  • パスワード: 大文字1文字と数字1文字を含む8文字以上である必要があります

送信ボタンは、$derivedルーンを使用して計算されたフォーム全体の有効性に基づいて動的に有効/無効になります。フォームが正常に送信されると、成功メッセージが表示され、$effectルーンを使用したクリーンアップにより3秒後にフォームがリセットされます。

この例は、Svelte 5のRunesが、Svelte 4のリアクティブステートメントやストアと比較して、より明示的で柔軟なリアクティビティシステムを提供する方法を示しています。

Prompt Overview

This prompt targets Svelte 5's new Runes API and asks an AI coding assistant to build a fully interactive form component that showcases three core primitives: $state for reactive variable declarations, $derived for computed values that update automatically, and $effect for side-effect handling. The result is a practical reference implementation where validation messages, error highlights, and submit-button states all respond instantly as the user types — without any manual event wiring or store boilerplate.

This kind of prompt is ideal for developers migrating from Svelte 4 or learning the Runes paradigm from scratch, since it grounds abstract concepts in a concrete, familiar UI pattern. It also works well as a starting template for login screens, registration flows, or any data-entry interface where instant feedback improves usability. To adapt it further, try requesting additional field types such as dropdowns or file inputs, ask for Zod-based schema validation, or specify a particular design system like Tailwind or shadcn-svelte to shape the visual output.

Was this prompt helpful?

Comments

Comments appear after moderation

この記事が役に立ったら投げ銭で応援

Apple Pay / Google Pay / カード (Visa/Mastercard/JCB/Amex) / Link / Alipay / WeChat Pay 対応 · Stripeで安全に決済

開発者が選ぶ最強ツール集

運営者が毎日使っているツール・ガジェット 6選

見る
Homeヘルプ