MCPcopy Index your code
hub / github.com/TanStack/form / App

Function App

examples/solid/simple/src/index.tsx:22–115  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20}
21
22function App() {
23 const form = createForm(() => ({
24 defaultValues: {
25 firstName: '',
26 lastName: '',
27 },
28 onSubmit: async ({ value }) => {
29 // Do something with form data
30 console.log(value)
31 },
32 }))
33
34 return (
35 <div>
36 <h1>Simple Form Example</h1>
37 <form
38 onSubmit={(e) => {
39 e.preventDefault()
40 e.stopPropagation()
41 form.handleSubmit()
42 }}
43 >
44 <div>
45 {/* A type-safe field component*/}
46 <form.Field
47 name="firstName"
48 validators={{
49 onChange: ({ value }) =>
50 !value
51 ? 'A first name is required'
52 : value.length < 3
53 ? 'First name must be at least 3 characters'
54 : undefined,
55 onChangeAsyncDebounceMs: 500,
56 onChangeAsync: async ({ value }) => {
57 await new Promise((resolve) => setTimeout(resolve, 1000))
58 return (
59 value.includes('error') && 'No "error" allowed in first name'
60 )
61 },
62 }}
63 children={(field) => {
64 // Avoid hasty abstractions. Render props are great!
65 return (
66 <>
67 <label for={field().name}>First Name:</label>
68 <input
69 id={field().name}
70 name={field().name}
71 value={field().state.value}
72 onBlur={field().handleBlur}
73 onInput={(e) => field().handleChange(e.target.value)}
74 />
75 <FieldInfo field={field()} />
76 </>
77 )
78 }}
79 />

Callers

nothing calls this directly

Calls 2

createFormFunction · 0.90
handleSubmitMethod · 0.65

Tested by

no test coverage detected