final-form / react-final-form

🏁 High performance subscription-based form state management for React
https://final-form.org/react
MIT License
7.38k stars 480 forks source link

getIn always returns undefined #696

Open BeauCarrel opened 4 years ago

BeauCarrel commented 4 years ago

Are you submitting a bug report or a feature request?

bug report

What is the current behaviour?

The getIn function given with the tools provided to mutators always returns undefined. I can't get it to work under any circonstances, complex or simple names, I've created a simpler version do demonstrate:

render() {
        return (
                <PopupDiv>
                    <Form onSubmit={this.onSubmit}
                          render={this.renderForm}
                          initialValues={locationData}
                          mutators={{
                              testMutator: ([name], state, tools) => {console.log(tools.getIn(state, name), state)}
                          }}
                    />
                </PopupDiv>
        );
    }

    renderForm = ({handleSubmit, submitting, form: { mutators: {testMutator}}}) => {
        return (

               ...

                <label>{strings.precision_country_label}
                    <Field name={'country'} component={'input'}/>
                </label>

                <button type={'button'} onClick={() => testMutator('country')}>Test</button>

                ...
        )
    }

The result of the log :

Screenshot 2019-12-12 at 10 26 38

What is the expected behavior?

It should return the value of the field that I request with the complexKey param. I've also logged the state param, and the field does exist with its value

Sandbox Link

What's your environment?

"react-final-form": "^6.3.3",
"react-final-form-arrays": "^3.1.1",
"final-form": "^4.18.6",
"final-form-arrays": "^3.0.2",
"react": "^16.9.0",
"react-dom": "^16.9.0",

I've only tested with Chrome (78.0.3904.108) on Mac

Other information

Thank you for your time, and this excellent package that I love!

UnDer-7 commented 3 years ago

same problem