[How to] Add a Calendar Date Picker To Your Form


Userlevel 7
Badge +1
  • Former Community Manager @ Unbounce
  • 831 replies


If your lead gen form requires a date or set of dates, you might be interested in hooking up a “date picker” widget to make the interaction as easy as possible. While this is a feature we will one day incorporate into the core form builder in Unbounce, you can use the following set of steps to get it working today.


🚨
This is not an official Unbounce feature. This functionality is based entirely on third party code, and has only been tested in limited applications. Since this isn’t a supported Unbounce feature, our support team will be unable to assist if things go awry. So if you are not comfortable with HTML, Javascript and CSS, please consider consulting an experienced developer.


Click Here for Instructions

Step 1: Add jQuery and jQuery UI

Open up the “Javascripts” panel (click the Javascripts button in the bottom left of the editor) and paste in the following:

<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script src="https://code.jquery.com/ui/1.13.0/jquery-ui.js"></script>

Call this script “jQuery” and set the placement to “Head”.

Step 2a: Add the jQuery UI stylesheet

Next, hop over to the “Stylesheets” screen (click the “Stylesheets” button in the bottom left of the editor) and paste in the following:

<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/smoothness/jquery-ui.css" />

Call this stylesheet “jQuery UI” and click “Save Code”.

Step 2b (Optional): Customize the look of your date picker

There are many different themes available to the jQuery UI, and the above step is making use of the “smoothness” theme. If you wish to use a different theme, follow these steps:

  1. Hop over to the jQuery Theme Editor.
  2. Click “Gallery” and browse through the available themes.
  3. When you find the one you like, make note of the template name (e.g., “Base”, in the image below).
  4. In the “jQuery UI” stylesheet you created in Step 2a above, replace the word “smoothness” in your tag with the template name of the theme you wish to use and click “Save Code”. If the template name contains more than one word, add a hyphen (-) between each word (e.g., “black-tie”).

For example if you wanted to use the jQuery “Sunny” theme you would change the link to:
<link rel="stylesheet" type="text/css" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/sunny/jquery-ui.css" />

There should only be ONE jQuery UI stylesheet being included on your page now.

Step 3: Add the date field to your form

You may already have this in your form, but the important part is finding out what the field is called. You’ll want to use just a “Single-line Text Field”:

Design%20Your%20Form%20Single%20Text%20Field

In this example I’m calling it “Start Date”. You’ll notice right under the Field Label input box, there’s some text “start_date”. This is the ID of your field, remember it for the next step

Step 4: Add the ‘date picker’ JavaScript code

Open up the Scripts dialogue again. Add a new script, call it “Date Picker” and set the placement to “Head”. Paste in the following code, and replace “start_date” with the form field ID that you took note of in the last step:

<script>
  $(function() {
    $( "#start_date" ).datepicker();
  });
</script> 

👉 Make sure the “#” symbol is included in front of the form field ID - otherwise, this script won’t work!

If you’re using an outdated version of jQuery UI, you will need to use the updated version (1.12.1). You can download this from the jQuery CDN page.

That’s it, you’re all done!

You can save and preview your page now, and clicking on the “Start Date” input field should show you something like this (depending on which theme you chose):

13%20PM

Selecting a date will populate the form field like so:

20%20PM


Remember to look at all the options of using this component if you want to get your hands dirty customizing it. There really are a ton of options, including changing the format of the date string that populates your form field. Let us know how it worked out for you!


35 replies

The datepicker works great!  However, users can still type random numbers into the field and the field accepts it.

 

Does anyone know how to require that what is typed into an unbounce form field is actually a date?

Hi Cam,

I was able to find a way to change the format of the date when using the date picker. 

To do this you will want to change the script in Step 4 to what I added below:
 

<script>
$(function() {
$( "#start_date" ).datepicker();
});
$( "#start_date" ).datepicker({
dateFormat: "dd-mm-yy"
});
</script>

This is script has a small addition which would allow you to set the order of dd/mm/yy.

You will want to make sure both instances of start_date match your form field ID. 

Thanks,

René

Badge

Hi, 

Has anyone been able to switch the format in which the dates are given?

I.e. my client is looking to send the D.O.B through in the following format dd/mm/yyyy

 

Any help is greatly appreciated!

Thanks

Is there a way to allow only weekdays for app’t and exclude weekends? so 7 days out minus weekends?

Any advice on how to add Date & Time? Thank you!

You may need to change the format of the date in order to make it work with Marketo. For instance, I had to modify the date produced by the calendar (MM/DD/YYYY) by replacing the “/” characters with “-” to validate the date against a javascript system date.

This was the replacement regex:
var purchaseDate = purchaseDay.replace(///g,"-");

However, if a date in another platform needs to be in the format YYYY-MM-DD, then you’d need to do a little bit more formatting to get the date to pass correctly into the other platform.

UPDATE: Just looked at Marketo’s API specifications. They need YYYY-MM-DD format.

Hello,
We added this date picker to one of our forms, but we are having trouble with the market integration. We’ve mapped the date picker field to a marketo field but it is not passing the data over. We keep getting an “invalid date” error. Can someone tell me what the field type should be in Marketo so that it passes through properly (i.e. date, text, etc.)? Any help would be greatly appreciated.

  • Carlos

Hi Hope you are Good
I’m facing issue in style
http://unbouncepages.com/pbj-friends/



Userlevel 2
Badge +1

Try the solution I have shared above, it worked for me.

Userlevel 2
Badge +1

I finally got this working!
Use this:

<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">

instead of this from the instructions:

<link rel="stylesheet" type="text/css" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/smoothness/jquery-ui.css" />

Worked for me. Let me know if it works for you.

Need help date picker not working.

https://book.cloudninecare.com/delivery-package-bangalore/

Can anyone please help?

Userlevel 7
Badge +3

Hey @tanyab,

Look into minDate and maxDate options for your calendar and that would solve your issue.

Best,
Hristian

Can anyone get limited amount of dates to work? I want to only allow customers to pick 7 days from current date?

Has anybody been able to get this to work? I think I have an older version of jquery but I’m not sure how to get a current version and get the calendar picker up and running. Any help would be appreciated 🙂

Hi there i don’t know if i’m posting in the right topic, but this is the closer one from my issue, so here is my problem : i have a custom calendar from calendly on my unbounce page and i want to make it a required field, i have some experiences with Html & css, but i’m like a very beginner of javascript, i know it could be simple with a custom javascript! do you have any ideas or tips that could help me ?
Capture d’écran 2020-02-21 à 10.46.46|690x138

Capture d’écran 2020-02-21 à 10.52.59

Hi Bruna! I’d love some help here - can’t get mine working either. Still shows a single text field after I added in JS for a sticky header and smooth scrolling. Thoughts?

Hey Jess,

Looking to edit the calendar to limited amount of dates. Any suggestions?

I’m also working fine in preview mode but not live - any tips on why? Tried ensuring my jquery ui loading instructions using 1.12.1 version but no luck?

Userlevel 5
Badge +4

Hello,

I’m having trouble getting this work with a multi-step 2 form (it is related ? i don’t know)
The field is a required one and when i select a date and try to move to the next field, it says “field is required” which is strange as there is numbers inside the field.

I tried to unselect “required field” and it’s working but i’m afraid people will try to leave the filed blank…

Here is the LP: https://mincir-avec.institut-phytotherapie.com/
–> it’s in french
–> it’s the fourth field.

Thanks in advance

Hi Khaerus,

even I am facing the same issue, its working in preview mode but not when published

[quote=“Jess, post:1, topic:11422”]
Hi All i try to follow this instruction and datepicker working in review but after publis date picker can’t running. does anyone experience the same thing ?

Hi all,

I have followed the instructions perfectly but it’s not working for some reason. Is anyone else having trouble?

Userlevel 3

Hey Thomas! 👋

Have you got this working? I would love to help you out on this one. 🙂

Userlevel 6
Badge +4

Great script! Is there a way to let users select more than 10 years back at the time for selecting year of birth?

When I add the script I can only select 10 years back at the time. Then the date picker reloads and lets me choose 10 more years. However for a 60 year old that might not be the most intuitive way of selecting their year of birth 😉

Any help appreciated!

I installed the scripts correctly but the calendar only shows up in “preview” mode and not the published website. Is there an extra step?

Reply