diff --git a/django/forms/fields.py b/django/forms/fields.py
index 3176ce6..1002642 100644
a
|
b
|
class FloatField(IntegerField):
|
289 | 289 | |
290 | 290 | def widget_attrs(self, widget): |
291 | 291 | attrs = super(FloatField, self).widget_attrs(widget) |
292 | | if isinstance(widget, NumberInput): |
| 292 | if isinstance(widget, NumberInput) and 'step' not in widget.attrs: |
293 | 293 | attrs.setdefault('step', 'any') |
294 | 294 | return attrs |
295 | 295 | |
… |
… |
class DecimalField(IntegerField):
|
377 | 377 | |
378 | 378 | def widget_attrs(self, widget): |
379 | 379 | attrs = super(DecimalField, self).widget_attrs(widget) |
380 | | if isinstance(widget, NumberInput): |
| 380 | if isinstance(widget, NumberInput) and 'step' not in widget.attrs: |
381 | 381 | if self.decimal_places is not None: |
382 | 382 | # Use exponential notation for small values since they might |
383 | 383 | # be parsed as 0 otherwise. ref #20765 |
diff --git a/tests/forms_tests/tests/test_fields.py b/tests/forms_tests/tests/test_fields.py
index fe11370..78b74ae 100644
a
|
b
|
class FieldsTests(SimpleTestCase):
|
282 | 282 | self.assertEqual(f.max_value, 1.5) |
283 | 283 | self.assertEqual(f.min_value, 0.5) |
284 | 284 | |
| 285 | def test_floatfield_widget_attrs(self): |
| 286 | f = FloatField(widget=NumberInput(attrs={'step': 0.01, 'max': 1.0, 'min': 0.0})) |
| 287 | self.assertWidgetRendersTo(f, '<input step="0.01" name="f" min="0.0" max="1.0" type="number" id="id_f" />') |
| 288 | |
285 | 289 | def test_floatfield_localized(self): |
286 | 290 | """ |
287 | 291 | Make sure localized FloatField's widget renders to a text input with |
… |
… |
class FieldsTests(SimpleTestCase):
|
392 | 396 | self.assertEqual(f.widget_attrs(NumberInput()), {'step': '1e-19'}) |
393 | 397 | f = DecimalField(max_digits=20) |
394 | 398 | self.assertEqual(f.widget_attrs(NumberInput()), {'step': 'any'}) |
| 399 | f = DecimalField(max_digits=6, widget=NumberInput(attrs={'step': '0.01'})) |
| 400 | self.assertWidgetRendersTo(f, '<input step="0.01" name="f" type="number" id="id_f" />') |
395 | 401 | |
396 | 402 | def test_decimalfield_localized(self): |
397 | 403 | """ |