Commit 40d6239d authored by Jérome Perrin's avatar Jérome Perrin

float fields were not able to display back string values (like in the case of validation failure)



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@18767 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 77882f91
...@@ -1244,7 +1244,10 @@ class FloatWidget(TextWidget): ...@@ -1244,7 +1244,10 @@ class FloatWidget(TextWidget):
original_value = value original_value = value
if input_style.find('%')>=0: if input_style.find('%')>=0:
percent=1 percent=1
value = float(value) * 100 try:
value = float(value) * 100
except ValueError:
return value
try : try :
float_value = float(value) float_value = float(value)
if precision: if precision:
......
...@@ -106,6 +106,12 @@ class TestFloatField(unittest.TestCase): ...@@ -106,6 +106,12 @@ class TestFloatField(unittest.TestCase):
self.assertEquals('12.34', self.field.render("12.34")) self.assertEquals('12.34', self.field.render("12.34"))
self.assertEquals('not float', self.field.render("not float")) self.assertEquals('not float', self.field.render("not float"))
def test_percent_style_render_string_value(self):
self.field.values['input_style'] = '-12.3%'
self.field.values['editable'] = 0
self.assertEquals('-12.34%', self.field.render("-0.1234"))
self.assertEquals('not float', self.field.render("not float"))
def test_render_big_numbers(self): def test_render_big_numbers(self):
self.field.values['precision'] = 2 self.field.values['precision'] = 2
self.field.values['editable'] = 0 self.field.values['editable'] = 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment