Open markhobson opened 8 months ago
This issue can be worked around with the following custom widget:
class RemoveLeadingZerosGovDateInput(GovDateInput): # type: ignore
"""
A GOV.UK date input widget that removes leading zeros from day and month fields.
"""
def map_gov_params(self, field: Field, **kwargs: str) -> dict[str, Any]:
params: dict[str, Any] = super().map_gov_params(field, **kwargs)
if field.raw_data is None and field.data:
day, month = field.data.strftime("%-d %-m").split(" ")
params["items"][0]["value"] = day
params["items"][1]["value"] = month
return params
Describe the bug The
GovDateInput
widget renders the day and month fields with leading zeros, for example02 03 2007
. This is contrary to what is recommended by the dates pattern which is to omit leading zeros.To Reproduce
Or formatted:
Expected behavior I would expect the day and month field values not to have leading zeros:
This behaviour is due to the format used in GovDateInput:
%d %m %Y
. To omit leading zeros we can use%-d %-m %Y
, although this is platform dependent.