question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Providing a onChange prop for <Field> should not overwrite the internal final-form onChange function

See original GitHub issue

Are you submitting a bug report or a feature request?

bug report

What is the current behavior?

When passing my own onChange prop it actually overwrites the final-form onChange function.

What is the expected behavior?

When passing my own onChange function to the <Field> component it should merge with the internal onChange function of final-form

Sandbox Link

https://codesandbox.io/s/w7pl6pqkrw

Try to select a value in the second dropdown. It’ll fire the custom myOnChange function but won’t select the value because it overwrites the final-form onChange function.

What’s your environment?

"final-form": "^3.0.0",
"react-final-form": "^2.1.1",
"react": "16.2.0",
"react-dom": "16.2.0",
node version: v8.9.1

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:6
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
mschipperheyncommented, Jun 6, 2018

IMHO this is a totally valid request. I consider this a bug.

7reactions
felixjungcommented, Jan 9, 2018

Hi,

Thanks for submitting the issue and providing an example. I don’t have any working knowledge of the library, yet, other than reviewing the docs. However, looking at your suggestion, I don’t think this is a valid request. How would you expect the library to know how to compose (merge) your myOnChange with its own onChange? And, given that you basically overwrite the default onChange, I don’t think it should. But, your problem can be solved by using the render prop API for fields and providing your own onChange handler.

I’ve updated your example with the solution I have in mind: https://codesandbox.io/s/3qlx8o98j5

To the maintainers: this piece of software looks awesome and the docs are great! Thanks a lot!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to listen to onChange of the Field component in React ...
A callback that will be called whenever an onChange event is fired from the underlying input. This callback allows to get "newValue" and...
Read more >
Final Form Docs – `<Field/>`
<Field/> accepts FieldProps and will call the render function with ... is to accept a value prop and somehow call the onChange callback...
Read more >
Custom onChange in React Final Form - JetRockets
Let's take a case when we need to call our own function to change a state of a specific field in a form...
Read more >
react-final-form - npm
Start using react-final-form in your project by running `npm i ... the field will not rerender if you change your validation function to...
Read more >
Input Components - React-admin - Marmelab
Refer to the documentation of each input component to see what inner classes you can override. validate. A function or an array of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found