0

The specified value "06-03-2019" does not conform to the required format, "yyyy-MM-dd".

I use Django internationalisation in a webapplication and for some reason suddenly I get this error in the developer tools on a form date input after changing the language to Dutch. On English everything works fine, the error is not shown and date is saved correctly. I use he standard django forms dateInput.

I searched the webs for hours, before turning to your help. Any suggestions would be greatly appreciated!

Thanks.

Gijsriet
  • 123
  • 9

2 Answers2

1

Actually, what solved the issue was setting it manually the other way around by adding format=('%Y-%m-%d').

        for field in date_fields:
        self.fields[field].widget = forms.DateInput(
            format=('%Y-%m-%d'),
            attrs={
                'type': 'date',
                'class': 'form-control',
                'max': now.strftime('%Y-%m-%d'),
                'data-msg-min': _("Kies een datum op of na {0}"),
                'data-msg-max': _("Kies een datum die niet in de toekomst ligt")
            },
        )
Gijsriet
  • 123
  • 9
0

The problem is probably caused by the Localization, you can disable it on your form like this:

class ExampleForm(forms.Form):
   date_field = forms.DateField(localize=False)

I usually just disable localization globally in the settings:

USE_L10N = False
p14z
  • 1,760
  • 1
  • 11
  • 17
  • Sadly, that doesn't solve my issue. I already tried both, but without any luck. Thanks for your suggestion, though. – Gijsriet Mar 13 '19 at 17:13
  • Did you try setting the date format manually? https://stackoverflow.com/questions/30911612/how-can-i-set-a-datefield-format-in-django-from-the-model – p14z Mar 13 '19 at 17:27