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.

event.preventDefault is not a function in onChange(event, value, previousValue, name)

See original GitHub issue

after upgrade react-redux to version 7.1.1 and redux-form to version 8.2.6… i found that preventDefault object is missing from the event params…

Here is my code…

<Field
     component={ReduxFormRadioGroup}
     formItemProps={{ className: 'operation-hours__option-container' }}
     label='Hours of Operation'
     name='operationHoursCategory'
     onChange={this.handleCategoryChange}
/>

handleDisabledDayChange = (event, value, previousValue, name) => {
        console.log(event, value, previousValue, name)
        event.preventDefault()
        ...
        .......
}

in "redux-form": "^7.2.0" and "react-redux": "^5.0.7": console.log(event) can see the preventDefault: ƒ preventDefault()

in redux-form": "^8.2.6" and "react-redux": "^7.1.1": console.log(event) do not have preventDefault: ƒ preventDefault()

this in result event.preventDefault() is not a function and break the application!

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
dereksandkampcommented, Feb 5, 2020

8.3.0 did not fix the problem for me.

For many of my inputs, I’m calling input.onChange(value) with the value of the input as the argument. These are the inputs that cause the problem. When an onChange is passed to the <Field /> from above these inputs, the first argument injected into the Field’s onChange is the value, not the event. Then there is no way to cancel the change event.

It is possible to fix this by updating my inputs to call input.onChange(event) with the event instead of the value as the first argument. Then any Field.onChange handlers will receive the event. However, this isn’t ideal for some inputs because the value that is attached to the change event is not always the value that I would like to propagate.

There are likely ways to work around this, but it seems like this wasn’t an intended change. Or if it was, the documentation should at least make it clear that in order to receive the event in the Field.onchange handler, you need to pass an event to input.onChange from within the input.

2reactions
armin-thcommented, Jan 29, 2021

Just want to note, this is still an issue in 8.3.7

Appreciate any work being put into this 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

preventDefault() not working for change event - Stack Overflow
You can't use preventDefault on change events because it's not cancelable: $("#text1").change(function(e) { alert(e.cancelable?
Read more >
Field - Redux Form
preventDefault () , the BLUR action will NOT be dispatched, and the value and focus state will not be updated in the Redux...
Read more >
Event.preventDefault() - Web APIs | MDN
The preventDefault() method of the Event interface tells the user agent that if the event does not get explicitly handled, its default ...
Read more >
w2grid.onChange | JavaScript UI - w2ui
Hi Vitmalina,. Why is the name of the field not provided in the event ? The event gives the recid, the previous value...
Read more >
Handle the Value Change Event - DevExtreme - DevExpress
If the handling function is not going to be changed during the lifetime of the UI component, assign it to the onValueChanged property...
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