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

feat: casting empty numberstring to null #1390

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

sodoojin
Copy link

Description

In the MVC web service, when receiving user input as object from the controller through form submit, each fields should be casted from string to suitable type.
and class-transformer returns 0 when converting empty string to number.

so, IsNotEmpty of class-validator doesn't work for number field because the number field user not input will be initialized to 0.

If class-transformer returns null when converting empty characters to numbers, then IsNotEmpty can be used for number fields as well.

Checklist

  • the pull request title describes what this PR does (not a vague title like Update index.md)
  • the pull request targets the default branch of the repository (develop)
  • the code follows the established code style of the repository
    • npm run prettier:check passes
    • npm run lint:check passes
  • tests are added for the changes I made (if any source code was modified)
  • documentation added or updated
  • I have run the project locally and verified that there are no errors

@diffy0712
Copy link

diffy0712 commented May 1, 2024

I do not think this should be added. This could cause other issues for existing users of this library.
I do believe that this problem should be handled via a custom Transformer in your application code.
Edit: In js Number('') will return 0, which is expected.

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

Successfully merging this pull request may close these issues.

None yet

2 participants