mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-29 12:58:31 -04:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user