From 415a36947cb4b8b61230698e13cca2df9400e245 Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Thu, 18 Jul 2013 22:01:51 -0400 Subject: Fixed #20765 -- Set small values of `step` using exponential notation. Browsers parse small factors of 10 as 0 under decimal notation. Thanks to Trac alias matklad for the report and Claude Paroz for the review. --- tests/forms_tests/tests/test_fields.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests/forms_tests') diff --git a/tests/forms_tests/tests/test_fields.py b/tests/forms_tests/tests/test_fields.py index f7d83503f4..dab67b4366 100644 --- a/tests/forms_tests/tests/test_fields.py +++ b/tests/forms_tests/tests/test_fields.py @@ -374,6 +374,17 @@ class FieldsTests(SimpleTestCase): self.assertEqual(f.clean('.01'), Decimal(".01")) self.assertRaisesMessage(ValidationError, "'Ensure that there are no more than 0 digits before the decimal point.'", f.clean, '1.1') + def test_decimalfield_widget_attrs(self): + f = DecimalField(max_digits=6, decimal_places=2) + self.assertEqual(f.widget_attrs(Widget()), {}) + self.assertEqual(f.widget_attrs(NumberInput()), {'step': '0.01'}) + f = DecimalField(max_digits=10, decimal_places=0) + self.assertEqual(f.widget_attrs(NumberInput()), {'step': '1'}) + f = DecimalField(max_digits=19, decimal_places=19) + self.assertEqual(f.widget_attrs(NumberInput()), {'step': '1e-19'}) + f = DecimalField(max_digits=20) + self.assertEqual(f.widget_attrs(NumberInput()), {'step': 'any'}) + def test_decimalfield_localized(self): """ Make sure localized DecimalField's widget renders to a text input with -- cgit v1.3