Providing a onChange prop for <Field> should not overwrite the internal final-form onChange function
See original GitHub issueAre 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:
- Created 6 years ago
- Reactions:6
- Comments:7 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
IMHO this is a totally valid request. I consider this a bug.
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 ownonChange
? And, given that you basically overwrite the defaultonChange
, I don’t think it should. But, your problem can be solved by using the render prop API for fields and providing your ownonChange
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!