Solved

Date picker validation

  • 31 August 2016
  • 6 replies
  • 91 views

So I am using the javascript/jquery to create a date picker field. ( http://documentation.unbounce.com/hc/en-us/articles/203799174?&_ga=1.151425657.1990160284.142473… )

How do I go about updating the javascript to prevent a user from selecting a date in the past?

icon

Best answer by Rob 10 October 2017, 02:06

View original

6 replies

Disregard…I figured it out.

I have the same problem. How did you get this sorted ?

Userlevel 6

Hi @Akshada try adding

minDate: 0

to the datepicker function. Setting the minDate value to 0 will prevent anyone from picking a date in the past.

Hope this helps!

Hi @Rob
Is there also a solution for pre-selecting a total timeframe?
For example if there is a promotion just for the next 3 weeks, I want the participants to choose a time just within this timeframe. what do I need to set as maxDate?

Userlevel 6

Hi @Markus_Danninger You can for sure do this using the available minDate and maxDate options of the datepicker() function. There are a few ways to define a date in this context. Personally I find the easiest and most readable way as something like this:

$("#datepicker").datepicker({
dateFormat: “dd-M-yy”,
minDate: “+1w”,
maxDate: “+2w”
});

The “+1w” and “+2w” are one week and two weeks from the current date. So the above would set a date range of one week, starting a week from today. You can also hard set a date using the date format specified in the function. For example: new Date(2018, 1 - 1, 1)

You can find a bit more info in the jQuery UI docs here http://api.jqueryui.com/datepicker/#option-maxDate

Hope this helps!

https://book.cloudninecare.com/ear-piercing/

Please help???

<script>
    document.getElementById("preferred_date").type = "date";
</script>

This is the code I'm using.

 

Could you share the updated javascript to prevent a user from selecting a date in the past and current date?

 

Reply