rivernews / appl-tracky-spa

An Application Tracking System to help job finders ease their out-of-control spreadsheet use tracking every job application record.
https://appl-tracky.shaungc.com
1 stars 0 forks source link

About how have field class take responsibility of setting initial value instead of the caller form #34

Open rivernews opened 5 years ago

rivernews commented 5 years ago

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:

  1. Prepare intialValues and other stuff, and pass them to <FormFactory> as props.
  2. Add fields to form by 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 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.

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)

Originally posted by @rivernews in https://github.com/rivernews/appl-tracky-spa/issues/19#issuecomment-489365680

rivernews commented 3 years ago

We can't remember specific details of the issue. But if it starts causing an issue e.g. scalability, we can always look back.