File: array.md | Updated: 11/15/2025
Search...
+ K
Auto
Docs Examples GitHub Contributors
Docs Examples GitHub Contributors
Docs Examples GitHub Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Maintainers Partners Support Learn StatsBETA Discord Merch Blog GitHub Ethos Brand Guide
Documentation
Framework
Solid
Version
Latest
Search...
+ K
Menu
Getting Started
Guides
API Reference
Examples
Framework
Solid
Version
Latest
Menu
Getting Started
Guides
API Reference
Examples
Solid Example: Array
==========================================================================================================================================================================================================================================================================================================================================================================================
Code ExplorerCode
Interactive SandboxSandbox
src
index.tsx
vite-env.d.ts
.gitignore
README.md
index.html
package.json
tsconfig.json
vite.config.ts
tsx
/* @refresh reload */
import { render } from 'solid-js/web'
import { createForm } from '@tanstack/solid-form'
import { Index, Show } from 'solid-js'
function App() {
const form = createForm(() => ({
defaultValues: {
people: [] as Array<{ age: number; name: string }>,
},
onSubmit: ({ value }) => alert(JSON.stringify(value)),
}))
return (
<div>
<form
onSubmit={(e) => {
e.preventDefault()
e.stopPropagation()
form.handleSubmit()
}}
>
<form.Field name="people">
{(field) => (
<div>
<Show when={field().state.value.length > 0}>
{/* Do not change this to For or the test will fail */}
<Index each={field().state.value}>
{(_, i) => (
<form.Field name={`people[${i}].name`}>
{(subField) => (
<div>
<label>
<div>Name for person {i}</div>
<input
value={subField().state.value}
onInput={(e) => {
subField().handleChange(e.currentTarget.value)
}}
/>
</label>
</div>
)}
</form.Field>
)}
</Index>
</Show>
<button
onClick={() => field().pushValue({ name: '', age: 0 })}
type="button"
>
Add person
</button>
</div>
)}
</form.Field>
<button type="submit">Submit</button>
</form>
</div>
)
}
const root = document.getElementById('root')
render(() => <App />, root!)
/* @refresh reload */
import { render } from 'solid-js/web'
import { createForm } from '@tanstack/solid-form'
import { Index, Show } from 'solid-js'
function App() {
const form = createForm(() => ({
defaultValues: {
people: [] as Array<{ age: number; name: string }>,
},
onSubmit: ({ value }) => alert(JSON.stringify(value)),
}))
return (
<div>
<form
onSubmit={(e) => {
e.preventDefault()
e.stopPropagation()
form.handleSubmit()
}}
>
<form.Field name="people">
{(field) => (
<div>
<Show when={field().state.value.length > 0}>
{/* Do not change this to For or the test will fail */}
<Index each={field().state.value}>
{(_, i) => (
<form.Field name={`people[${i}].name`}>
{(subField) => (
<div>
<label>
<div>Name for person {i}</div>
<input
value={subField().state.value}
onInput={(e) => {
subField().handleChange(e.currentTarget.value)
}}
/>
</label>
</div>
)}
</form.Field>
)}
</Index>
</Show>
<button
onClick={() => field().pushValue({ name: '', age: 0 })}
type="button"
>
Add person
</button>
</div>
)}
</form.Field>
<button type="submit">Submit</button>
</form>
</div>
)
}
const root = document.getElementById('root')
render(() => <App />, root!)
