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

DecimalField validation turns '0' into empty string #57

Closed
MattFisher opened this issue Jan 27, 2015 · 1 comment
Closed

DecimalField validation turns '0' into empty string #57

MattFisher opened this issue Jan 27, 2015 · 1 comment

Comments

@MattFisher
Copy link

The line value = value.replace(/^0+/, '') at https://github.com/insin/newforms/blob/react/lib/fields.js#L440 within DecimalField.prototype.clean turns the string "0" into "", which is later returned for storage in cleaned_data.

It is also fed into this.runValidators(parseFloat(value)) at https://github.com/insin/newforms/blob/react/lib/fields.js#L482, and I haven't checked whether it will validate if max and min values have been set.

A simple but slightly hacky solution would be:

if (value !== '0') {
    value = value.replace(/^0+/, '')
}
@insin insin closed this as completed in 924c300 Jan 27, 2015
@insin
Copy link
Owner

insin commented Jan 27, 2015

Thanks for the bug report, a proper native decimal type can't come too soon 😁

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