Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
etoler1841 opened this issue Jan 2, 2020 · 0 comments

Comments

@etoler1841
Copy link

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."

notAro14 pushed a commit that referenced this issue Mar 11, 2021
Context: When two or more Fields are used either inside the Conditional component or both
in their own Conditional with the same show condition, only the last
Field receive its initial value set in item attribute via Formol
component.

The cause: when a Field is mounted, the register function is executed to
register the component in transientItem variable. But due to the async
nature of setState, the transientItem between Fields registration stays
the same.

I think this commit is an attempt to fix the bug c12d07c
But it seems to appear again #62
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant