1
I am working with Django and using a datepicker to select the date in a form field:
<h3>Data de recebimento</h3>
{{ form.creation_date }}
<script>
$(function () {
$("#id_creation_date").datepicker({
format:'dd/mm/yyyy',
});
});
</script>
In the creation form, when clicking appears the calendar in the current month and the date is saved correctly, but when I edit a form, when clicking on the date field the calendar displays the year 1911:
Is it possible to set the default month to be displayed? The strange thing is that when the field is empty it is already done.
Note: in Django the ids are automatically generated with the name of the field with "id_" in front, so the field creation_date
is referred to as id_creation_date
and this apparently has nothing to do with the problem.
<!-- Datepicker -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/datepicker/0.6.5/datepicker.min.css" integrity="sha256-b88RdwbRJEzRx95nCuuva+hO5ExvXXnpX+78h8DjyOE=" crossorigin="anonymous" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/datepicker/0.6.5/datepicker.min.js" integrity="sha256-/7FLTdzP6CfC1VBAj/rsp3Rinuuu9leMRGd354hvk0k=" crossorigin="anonymous"></script>
Before displaying in the view, you need to convert the server date to the desired format.
– iamdlm
I have to convert the date that was saved to the creation form so that the datepicker shows the correct month?
– Leila
Yes, you can do this directly with the query in the database or on the server before returning the date to the client.
– iamdlm