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

Cast checkbox value to string explicitly #2528

Merged

Conversation

Toleckk
Copy link
Contributor

@Toleckk Toleckk commented Aug 8, 2020

Fix rare error 'value.includes is not a function', that appears on controlled form with checkboxes array resetting, if fields order was changed.

Steps to reproduce the behavior:

  1. Go to https://codesandbox.io/s/clever-pond-zjequ
  2. Add few fields
  3. Click on any checkbox but last

Expected behavior
Value of checkbox should change after click

image

@codesandbox-ci
Copy link

codesandbox-ci bot commented Aug 8, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit c298213:

Sandbox Source
react-hook-form/react-hook-form: app Configuration
ecstatic-chaplygin-p862o PR

src/useForm.ts Outdated
(checkboxRef.checked = (value as string).includes(
checkboxRef.value,
)),
(checkboxRef.checked = (value as string | boolean)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String(value) is perhaps shorter? (see if can save few bytes)

@bluebill1049
Copy link
Member

Thanks @Toleckk for the PR 👍

@bluebill1049 bluebill1049 merged commit 93e7ca0 into react-hook-form:master Aug 9, 2020
@Toleckk Toleckk deleted the fix-checkbox-value-type-cast branch August 9, 2020 13:08
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

Successfully merging this pull request may close these issues.

2 participants