Skip to content

2.2 NestedFields

Avram Walden edited this page May 2, 2024 · 5 revisions

Provides context for nesting inputs.

const user = {
  firstName: 'Finn',
  preferences: {
    princess: 'Bubblegum',
    sword: 'Scarlet'
  }
}

const PageWithFormOnIt = () => {
  return (
    <Form model="user" data={ { user } } to={ `users/${user.id}` } method="patch">
      <TextInput name="firstName" label="First Name" />

      <NestedFields model="preferences">
        <TextInput name="princess" label="Favorite Princess" />
        <TextInput name="sword" label="Favorite Sword" />
      </NestedFields>
    </Form>
  )
}

This will make the inputs above sync their values with data.preferences.princess and data.preferences.sword respectively. It's just a convenience for making it visually clear that the inputs are nested.

Clone this wiki locally