Don’t reformat numbers if there are errors

It’s confusing to at the same time:
1. change what you’ve inputted
2. tell you it’s wrong

This commit makes it so that 1. only happens if 2. doesn’t.
This commit is contained in:
Chris Hill-Scott
2019-02-27 12:05:28 +00:00
parent a24c853dce
commit 61ac7fa069
2 changed files with 42 additions and 5 deletions

View File

@@ -181,17 +181,17 @@ class ForgivingIntegerField(StringField):
if valuelist:
valuelist[0] = valuelist[0].replace(',', '').replace(' ', '')
value = valuelist[0].replace(',', '').replace(' ', '')
try:
valuelist[0] = int(valuelist[0])
value = int(value)
except ValueError:
pass
if valuelist[0] == '':
valuelist[0] = 0
if value == '':
value = 0
return super().process_formdata(valuelist)
return super().process_formdata([value])
def pre_validate(self, form):
@@ -210,6 +210,12 @@ class ForgivingIntegerField(StringField):
def __call__(self, **kwargs):
if self.get_form().is_submitted() and not self.get_form().validate():
return super().__call__(
value=(self.raw_data or [None])[0],
**kwargs
)
try:
value = int(self.data)
value = '{:,.0f}'.format(value)