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

NumberMask: erroneous behavior when using allowEmpty with initialValues #37

Closed
1 of 6 tasks
renato-bohler opened this issue May 12, 2018 · 3 comments · Fixed by #66
Closed
1 of 6 tasks

NumberMask: erroneous behavior when using allowEmpty with initialValues #37

renato-bohler opened this issue May 12, 2018 · 3 comments · Fixed by #66
Assignees
Labels
bug Something isn't working number mask Refers to the `createNumberMask`

Comments

@renato-bohler
Copy link
Owner

What are you reporting?

  • Bug
  • Feature request
  • Code refactor
  • Continuous Integration (CI) improvement
  • Changes in documentation (docs)
  • Other (describe)

What is the current behavior?

When a Field which has an initial value is using a number mask with the allowEmpty option set, it is not possible to set the input value to zero. Also, in this case, instead of setting the Field's value to undefined, it sets to an empty string.

issue37

What is the expected behavior?

We should be able to set the Field to 0 in this case and the value when the input is empty should be undefined or null.

Sandbox Link

https://codesandbox.io/s/n4k073xzj

What's your environment?

Version: 1.1.3

Other information

This is related to redux-form/redux-form#3946. The only viable way to fix it is changing may be changing the normalize's return to null for allowEmpty (which makes more sense to me), but this may be a breaking change.

@renato-bohler renato-bohler added bug Something isn't working number mask Refers to the `createNumberMask` labels May 12, 2018
@mitchvoll
Copy link

This returns an empty string for the normalize function if allowEmpty is set. The API docs say that if allowEmpty is set then undefined will stored. Could this be part of the issue?

@renato-bohler
Copy link
Owner Author

@mitchvoll redux-form's change action will not set the Field value to undefined if its payload is undefined (in fact it will do nothing if that's the case). One way to set undefined to the Field with this action is to set the payload to an empty string, but that only works if the target Field has no initial values - and that's the cause of this issue.

There's more information here: redux-form/redux-form#3946 (comment).

I think the only way to really solve this for the current version of redux-form is to set the value to null instead of undefined (the change action will set to null if the payload is null), but that will cause a breaking change.

@renato-bohler renato-bohler self-assigned this Jan 23, 2019
renato-bohler added a commit that referenced this issue Feb 25, 2019
This change had to be made because of issue #37

BREAKING CHANGE: default empty value is now null instead of empty string
Closes Closes #37
@renato-bohler renato-bohler mentioned this issue Feb 25, 2019
renato-bohler added a commit that referenced this issue Feb 25, 2019
<a name="2.0.0"></a>
# [2.0.0](v1.3.0...v2.0.0) (2019-02-25)

### Bug Fixes

* **createNumberMask:** changes the default empty value to null ([d2f83f7](d2f83f7)), closes [#37](#37) [#37](#37)

### BREAKING CHANGES

* **createNumberMask:** default empty value is now null instead of empty string
@renato-bohler
Copy link
Owner Author

🎉 This issue has been resolved in version 2.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working number mask Refers to the `createNumberMask`
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants