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 is not set as touched #56

Closed
iamvanja opened this issue Jun 12, 2019 · 2 comments
Closed

Checkbox is not set as touched #56

iamvanja opened this issue Jun 12, 2019 · 2 comments

Comments

@iamvanja
Copy link

Consider

<Formik
  ...
  render={() => (
    <Form>
      <FormItem name='rememberMe'>
        <Checkbox name='rememberMe'>
          Remember me
        </Checkbox>
      </FormItem>
    </Form>
  )}
/>

Toggling this checkbox does not set rememberMe field as touched.

@jannikbuschke
Copy link
Owner

fixed in v1.1

@iamvanja
Copy link
Author

Appreciate the quick resolution on this, but I don't think this is fully resolved.
To allow custom onChange while still internally updating Formik state, prop onChange should not overwrite existing onChange. Instead, existing (internal) onChange should check if the user onChange is passed as a prop and execute it if so.

So instead of

...
onChange={v => {
  setFieldValue(name, v.target.checked)
  setFieldTouched(name, true)
}}
{...restProps}
...

something like this

...
{...restProps}
onChange={v => {
  setFieldValue(name, v.target.checked)
  setFieldTouched(name, true)
  restProps.onChange && restProps.onChange(v)
}}
...

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

2 participants