diff options
| author | Simon Charette <charette.s@gmail.com> | 2013-07-18 22:01:51 -0400 |
|---|---|---|
| committer | Simon Charette <charette.s@gmail.com> | 2013-07-19 23:31:15 -0400 |
| commit | 415a36947cb4b8b61230698e13cca2df9400e245 (patch) | |
| tree | 9591e0724eb62931c8cb3990cb44616e1a3b3289 /django | |
| parent | 6d52844b9b3c0bd18eea03ac9dc499782b84c36b (diff) | |
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.
Diffstat (limited to 'django')
| -rw-r--r-- | django/forms/fields.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py index c4bc3fa88c..7711cd65ad 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -370,8 +370,14 @@ class DecimalField(IntegerField): def widget_attrs(self, widget): attrs = super(DecimalField, self).widget_attrs(widget) - if isinstance(widget, NumberInput) and self.decimal_places: - attrs['step'] = '0.%s1' % ('0' * (self.decimal_places - 1)) + if isinstance(widget, NumberInput): + if self.decimal_places is not None: + # Use exponential notation for small values since they might + # be parsed as 0 otherwise. ref #20765 + step = str(Decimal('1') / 10 ** self.decimal_places).lower() + else: + step = 'any' + attrs.setdefault('step', step) return attrs |
