You are viewing limited content. For full access, please sign in.

Question

Question

limit date picker to previous 6 days

asked on October 5, 2021

I see posts on here about not allowing any future dates in the date picker, but is there some good javascript to limit the date picker to the "previous 6 days" from current date?

1 0

Answer

SELECTED ANSWER
replied on October 6, 2021

For anyone with a similar request, we found this bit of code to work perfectly for just the last 6 days and nothing else before or after:

   function isCorrectDate(n) {
   var daybefore = new Date(new Date().setDate(new Date().getDate()-6))
                var today = new Date(new Date().setDate(new Date().getDate()))
  
    return (n>=daybefore&&n<=today);
  }
  function checkDate(n) {
    return[isCorrectDate(n),""];
  }
  function checkField(input, inst) {
    if ($(input).closest('li').hasClass('myDate')) {
      $(input).datepicker("option", {beforeShowDay: checkDate});
    }
  }
  $.datepicker.setDefaults( {beforeShow: checkField} );

 

1 0

Replies

replied on October 6, 2021

Hi Brian,

 

There are several examples that can be used. I would suggest you to work with the code presented in this thread as a guide:
https://answers.laserfiche.com/questions/75138/I-want-to-prevent-user-from-picking-a-date-greater-than-today#75186

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.