initialValues

Specification

An object that describes initial values of the fields.

Definition

1
type InitialValues = {
2
[fieldName?: string]: any,
3
[fieldGroup?: string]: {
4
[fieldName?: string]: any,
5
},
6
}
Copied!

Priority

There are multiple way to affect initial value of a field. The first value found in the list below will be used as the initial value for a field (sorted by priority):
  1. 1.
    Form.props.initialValues
  2. 2.
    Field.props.initialValue
  3. 3.
    FieldClass.initialValue

Example

1
import React from 'react'
2
import { Form, Field } from 'react-advanced-form'
3
import { Input } from 'react-advanced-form-addons'
4
5
export default class ExampleForm extends React.Component {
6
render() {
7
return (
8
<Form initialValues={{
9
username: 'admin',
10
billingAddress: {
11
firstName: 'John',
12
lastName: 'Maverick',
13
},
14
deliveryAddress: {
15
firstName: 'Cathaline',
16
lastName: 'Sunwell',
17
},
18
}}>
19
<Input name="username" />
20
21
<Field.Group name="billingAddress">
22
<Input name="firstName" />
23
<Input name="lastName" />
24
</Field.Group>
25
26
<Field.Group name="deliveryAddress">
27
<Input name="firstName" />
28
<Input name="lastName" />
29
</Field.Group>
30
</Form>
31
)
32
}
33
}
Copied!
Field's group must also be reflected in the nesting of initialValues keys.
Last modified 3yr ago