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

[Feature Request]: Set a Field's Value From Another Field's onChange #116

Open
christinanate opened this issue Jul 20, 2023 · 3 comments
Open
Labels
enhancement New feature or request needs triage Needs attention from the HouseForm maintainers

Comments

@christinanate
Copy link

christinanate commented Jul 20, 2023

Description

I need an update to one field's value to also update another field's value.

Describe the solution you'd like

 <Form onSubmit={(values) => console.log(values)}>
      {({ value: formValues }) => (
    <Field>
              {({ value, setValue }) => (
                <>
                  <Select
                    onChange={(value) => {
                      setValue(value)
                      formValues.setFieldValue('anotherField') = 'new value'
                    }}
                  >
                   ...
      </Field>
)

The onSubmit function's values should log both fields updated values.

Describe alternatives you've considered

No response

@christinanate christinanate added enhancement New feature or request needs triage Needs attention from the HouseForm maintainers labels Jul 20, 2023
@babycourageous
Copy link
Contributor

Hi! I'm stumbling onto the same bump in the road... did you ever find any solution to this?

I thought mebbe directly changing the value from the Form render prop would do the trick but alas looks like that only takes effect after another form item is dirtied.

@GuilhermeAmado
Copy link

Any updates on this?

@Qnedy
Copy link

Qnedy commented Aug 31, 2023

the only way I was able to do this was, inside the onChange, get from DOM the input element with the name I want to change the value, and programmatically change its value :/

there is also a functionality in the Field called listenTo that can work for you @christinanate. But I still think that you will have to manipulate DOM elements. The only form method the callback function from onChangeValidate (for example) gives you is the getFieldValue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs triage Needs attention from the HouseForm maintainers
Projects
None yet
Development

No branches or pull requests

4 participants