From 76f6eaeb5e6fd56af3138926676aeddfed9c54ea Mon Sep 17 00:00:00 2001 From: Alexander Parrill Date: Tue, 19 Nov 2024 12:51:01 -0500 Subject: [PATCH] Fix number extra field not accepting decimals It used a NumerInput widget, but the default step of a `` is 1, so the browser only let integers be submitted. This adds `step="any"` to the widget to allow any number. Fixes #552 --- ghostwriter/commandcenter/models.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ghostwriter/commandcenter/models.py b/ghostwriter/commandcenter/models.py index 258635202..856b23ee7 100644 --- a/ghostwriter/commandcenter/models.py +++ b/ghostwriter/commandcenter/models.py @@ -357,6 +357,10 @@ class ExtraFieldType(NamedTuple): # Returns an "empty" value empty_value: Callable[[], Any] +def float_widget(*args, **kwargs): + widget = forms.widgets.NumberInput(*args, **kwargs) + widget.attrs.setdefault("step", "any") + return widget EXTRA_FIELD_TYPES = { "checkbox": ExtraFieldType( @@ -390,7 +394,7 @@ class ExtraFieldType(NamedTuple): "float": ExtraFieldType( display_name="Number", form_field=lambda *args, **kwargs: forms.FloatField(required=False, *args, **kwargs), - form_widget=forms.widgets.NumberInput, + form_widget=float_widget, from_str=float, empty_value=lambda: 0.0, ),