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

checkbox field do not trigger change event. Custom onChange passed to props also doesn't work #3369

Open
pjarmalavicius opened this issue Sep 1, 2017 · 16 comments

Comments

@pjarmalavicius
Copy link

pjarmalavicius commented Sep 1, 2017

Version: 7.0.3

Check / uncheck doesn't trigger "redux-form/CHANGE" action

@jokezer
Copy link

jokezer commented Sep 3, 2017

I have the same issue with radio input in 7.0.3.
When I click on radio input, I get

@@redux-form/FOCUS
@@redux-form/BLUR
@@redux-form/FOCUS

And no change event.
Checkboxes work fine.

@jokezer
Copy link

jokezer commented Sep 3, 2017

I created a custom component for radio button, and it works fine without onBlur prop.

@svengau
Copy link

svengau commented Sep 4, 2017

Same as @jokezer

Here is the working code:

function MyCustomRadioInput(props) {
  const { input: { onBlur, ...rest } } = props;
  return <input type="radio" {...rest} />;
}
<Field
   name="..."
   component={MyCustomRadioInput}
   value="..."
/>

@likerRr
Copy link

likerRr commented Oct 3, 2017

I found extremely strange issue with checkboxe's onChange event. I bunlde my code via webpack for development and then serve it via browser-sync:

    browserSync.init({
        serveStatic: ['build'],
        server: {
          baseDir: `build/${projectType}`,
          middleware: [
            historyFallback(),
          ],
        },
      });

So when I serve it via browser-sync, event doesn't trigger, but if I serve it via simple node server - event triggers :) So I assume that browser sync adds some code which breaks my code. Has anyone faced such strange behavior?

@seberik
Copy link

seberik commented Oct 3, 2017

@likerRr I observed the same for out code base. I could not find why onChange was not triggered for radio/checkbox inputs but the issue is not occurring in the compiled version.

@svengau
Copy link

svengau commented Oct 6, 2017

Indeed, BrowserSync client seems to have a patch for IE to force change, which is not compatible with redux-form:

/**
 * Force Change event on radio & checkboxes (IE)
 */
utils.forceChange = function (elem) {
    elem.blur();
    elem.focus();
};

A quick and dirty fix: use browserSync.init({minify: false, ...), and patch the source with:

sed -i -- 's/bs.utils.forceChange(elem);/\/\/CODE REMOVED;/g' node_modules/browser-sync-client/dist/index.js

@seberik
Copy link

seberik commented Oct 6, 2017

I disabled ghost-mode (https://browsersync.io/docs/options#option-ghostMode) and it seems to work.

@erikras
Copy link
Member

erikras commented Oct 6, 2017

There's a chance this might be fixed in v7.1.0, as it included a lot of fixes around checkboxes and deepEqual(). Can you confirm?

@seberik
Copy link

seberik commented Oct 8, 2017

I could still reproduce the problem with redux-form v7.1.0 but I think that the problem, at least for me is browser-sync.

@likerRr
Copy link

likerRr commented Oct 9, 2017

@seberik @erikras Can we somehow solve it with browser-sync's team?

@Anandks1993
Copy link

Anandks1993 commented Nov 15, 2017

@erikras I too faced the same issue, for checkbox, validation was triggered only after onblur. But this happened when I used state to handle the checked status of checkbox. When I changed the component to stateless it worked fine.

@crystalena
Copy link

ghostMode: false did the trick, thanks @seberik

@dmitru
Copy link

dmitru commented Dec 18, 2018

For me the problem was caused by BrowserSync too.
So frustrating! But glad I found the solution - thanks. 👍

@wahlg
Copy link

wahlg commented Jul 25, 2019

I'm experiencing this issue with redux form 7.4.2, and it is not due to using browser-sync. The first time that a checkbox is unchecked, it does not dispatch the @@redux-form/CHANGE event, but on subsequent toggles it does.

@ArtemUstilov
Copy link

@wahlg did you fin solution?

@iamandrewluca
Copy link
Member

Can someone provide a https://codesandbox.io with the issue? I tried but can't reproduce.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests