We can specify initialValue when newing inputfieldprops with a initial = {...} arg.
Can we just use Formik's values and not passing a initialValue? One challenge is we need to populate existing values for update form.
Components
The application status form.
Two things:
Prepare intialValues and other stuff, and pass them to <FormFactory> as props.
Add fields to form by new FormFieldProps(fieldName, label, ...).
The LinkField
Have no direct relation w/ initialValue. But LinkField contains the structure of the field and knows the key of the field in both values and initialValue.
LinkField can actually pass in a Link instance, so it works for both create & update form. Then store the initialValues in local. The form factory will have to access them from the LinkField instance. You can use a get function though.
The form factory
Passes initialValue=this.props.intialValue on <Formik />. If we need to modify initialValue at the beginning only and don't need update ... we can still use local state as this.state.initialValue.
Also has the formFieldPropsList passed in. If initialValue info is there, we can append that to this.state = {initialValue: ... in constructor.
Execution
Setup of initialValues will occur in LinkField (LinkFieldProps class, more precisely)
[ ] Set initialValues in LinkField.
[ ] Make sure LinkField accepts a Link instance for update form to populate the correct initial values.
[ ] Use the Link instance to generate initialValues for LinkField
[ ] Write a public function in LinkFieldProps class for other components to access initialValues of this field. The caller will use initialValues = { ...LinkFieldProps.initialValues(), ... } to merge the form's initialValues together.
[ ] application status form refactor to use LinkField
[ ] In form factory, implement componentDidMount() and loop through this.props.FieldPropsList. If LinkFieldProps, then call .initialValues() to pull out initial values. Collect all initial values, and set local variables for <Formik initialValues={this.initialValues} /> .
About how to set Initial value
Can we just use Formik's
values
and not passing a initialValue? One challenge is we need to populate existing values for update form.Components
Two things:
<FormFactory>
as props.new FormFieldProps(fieldName, label, ...)
.Have no direct relation w/ initialValue. But LinkField contains the structure of the field and knows the key of the field in both
values
andinitialValue
.LinkField can actually pass in a Link instance, so it works for both create & update form. Then store the initialValues in local. The form factory will have to access them from the LinkField instance. You can use a get function though.
Passes
initialValue=this.props.intialValue
on<Formik />
. If we need to modify initialValue at the beginning only and don't need update ... we can still use local state asthis.state.initialValue.
Also has the
formFieldPropsList
passed in. If initialValue info is there, we can append that tothis.state = {initialValue: ...
in constructor.Execution
Setup of initialValues will occur in LinkField (LinkFieldProps class, more precisely)
initialValues = { ...LinkFieldProps.initialValues(), ... }
to merge the form's initialValues together.componentDidMount()
and loop throughthis.props.FieldPropsList
. If LinkFieldProps, then call.initialValues()
to pull out initial values. Collect all initial values, and set local variables for<Formik initialValues={this.initialValues} />
.Originally posted by @rivernews in https://github.com/rivernews/appl-tracky-spa/issues/19#issuecomment-489365680