Thanks Kasper,
I utilized the suggestion you shared, and implemented it with a custom template tag, and now am able to restrict it.
On Fri, Jan 22, 2021 at 2:46 PM Kasper Laudrup <laudrup@stacktrace.dk> wrote:
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
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c56ecb88-6007-107c-e52f-c72f09f05f2a%40stacktrace.dk.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALQo0B_a2AF_oGB9MZxPhpiiKyhSRpLeiAgYqpwd_U3ynPeQMg%40mail.gmail.com.
No comments:
Post a Comment