Hi Maynak,
On 22/01/2021 21.34, Mayank Tripathi wrote:
> Hi All,
>
> I am look for a solution where I can restrict the user to select date
> from current month only instead of selecting any other month or year.
>
> Currently user can select past month as well, have to restrict for
> current month only in date picker.
>
It seems like the HTML date input field has attributes for setting the
min and max value:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date#additional_attributes
Setting these attributes to the first and last day of the month for the
widget ought to work:
https://docs.djangoproject.com/en/3.1/ref/forms/widgets/#django.forms.Widget.attrs
Of course, you still need to ensure that the client doesn't send an
invalid/unexpected date.
I haven't tested this, but that's what I'd try to do at least.
Hope that helps.
Kind regards,
Kasper Laudrup