Kozea / formol

An opinionated react form framework.
MIT License
189 stars 17 forks source link

Fields inside <Conditional> do not immediately populate in validator object #62

Open etoler1841 opened 4 years ago

etoler1841 commented 4 years ago

Fields placed inside a <Conditional> only populate in the validator object after another field is modified.

const formValidator = v => {
  console.log(v)
  // Validation
}

<Formol onSubmit={doFormStuff} validator={formValidator}>
  <Field name="yesOrNo" type="radio-set" choices={['Yes', 'No']}>Yes or no?</Field>
  <Conditional show={({ yesOrNo }) => yesOrNo === 'No'}>
    <Field name="whyNot">Really? Why not?</Field>
  </Conditional>
  <Field name="anotherField">Another field</Field>
</Formol>

After choosing "no," the object should be { yesOrNo: 'No', whyNot: null, anotherField: null }. Instead, the resulting object is just { yesOrNo: 'No', anotherField: null }. Even submitting the form won't cause the key to populate; it only shows up after changing "Another field."