Start learning with our library of video tutorials taught by experts. Get started

View Source

006 Creating a date picker for your forms with jQuery


From:

View Source

with Ray Villalobos

Video: 006 Creating a date picker for your forms with jQuery

Hello! This is Ray Villalobos and welcome to View Source. This week we're checking out jQuery UI and using it to display a pop-up calendar inside a form field. So if you're always looking for a cool date, then it's time to View Source. jQuery UI is a collection of user interface tools that is available as a separate download. The library is highly customizable and can be quite a large download when you include the entire thing. So chances are you'll want to customize it and load only what you need, but before you do that you'll probably want to take a look at the large library of styles available for the jQuery UI widgets.

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
Please wait...
View Source
2h 10m Intermediate Jan 20, 2012 Updated May 25, 2012

Viewers: in countries Watching now:

The View Source weekly series offers 10-minute projects on intermediate and advanced web design topics, covering technologies such as HTML, PHP, jQuery, and CSS, as well as content management solutions like WordPress and integration with Twitter, YouTube, and more. Each movie in the course is self-contained and shows how to accomplish an interesting effect and/or technique. Example projects include creating datepickers and custom photo galleries, and mapping and geotagging with Google Maps.

Topics include:
  • Creating a custom URL in WordPress
  • Adding breadcrumb links to sites
  • Creating a toggle button with jQuery
  • Adding Twitter feeds to a site
  • Adding PayPal buttons to pages
  • Uploading photos to your web site
  • Embedding videos for different browsers and devices
  • Parsing and placing a YouTube video feed
Subjects:
Web Web Design Projects
Software:
WordPress
Author:
Ray Villalobos

006 Creating a date picker for your forms with jQuery

Hello! This is Ray Villalobos and welcome to View Source. This week we're checking out jQuery UI and using it to display a pop-up calendar inside a form field. So if you're always looking for a cool date, then it's time to View Source. jQuery UI is a collection of user interface tools that is available as a separate download. The library is highly customizable and can be quite a large download when you include the entire thing. So chances are you'll want to customize it and load only what you need, but before you do that you'll probably want to take a look at the large library of styles available for the jQuery UI widgets.

So you'll want to go into this link right here and find the Datepicker section, click on that, and take a look at the different options for the Datepicker. So our input field is going to look something like this when you click it, and you could see that there are a lot of different themes you can use. So right here from the right-hand side you can click on this and switch the theme out to something else. I want to use one called Pepper Grinder. So I'm going to click on that, take a look at it, and from here I can take a look at the different options.

So for example, you may want to format the date, and to format the date you could choose from this pop-up right here, and after you're done customizing how you want your date to look, you could View Source right here and take a look at how that function needs to be set up. So there's a lot of options here, but let's get our own version of this started. Before we do that, we're going to go back into jQuery and click on this link called Build custom download, as I mentioned the entire jQuery UI library is quite large, so you should probably either use the Google CDN, the contact delivery network, that has a copy of jQuery that a lot of sites use.

If a site has already loaded that version of the jQuery UI when somebody clicks to go to your page and they've already loaded the library from somewhere else, then it will already be cached in their browser and load up a lot quicker. So in here you want to select the components that you want to load. So I'm going to deselect all the components, and I want to find just the Datepicker one, click on that, and then I want to come over here and make sure that I choose the theme that I want to download. So I am going to click on Pepper Grinder, because that's the one that I picked from the other page, and click on this Download link.

Once it finishes downloading, then find it in your downloads folder, and you want to open up this folder and find the CSS file for pepper-grinder so that you can use it in your own project. Now you will want to copy the images somewhere in your project. I have already copied all of these images into my images folder. You'll also want to copy the jQuery custom CSS file that it downloads, I've already loaded that and I have renamed it peppergrinder, because this is a long name.

Finally, you may want to include the jQuery version that you've customized. In my case I am going to be using the Google CDN, so I'm not going to use that version of the jQuery file. I have already placed a version of the jQuery UI minified JavaScript version that is available from Google CDN. I am only going to need that when I am working locally and I want to make sure I can preview my project even when I don't have a web connection. So I want to open up a preview, I am holding on the Option key, and clicking on Preview right here, and you'll see that we have the most basic form code right here.

It doesn't really do very much. We have a label right now for this field, and this is the only field we have on the form. The important thing is we have an input filed. We've given it a name and a type. The important thing is that the id needs to be datepicker, because jQuery UI is going to pick that up. So we'll go to our codesnippets and we need to load the scripts from Google CDN with an alternative version for our local development environment. So I am going to copy that, and go back into my index file and I'm going to paste the jQuery code right here.

All this is doing is loading up two versions of the library, you're going to need the jQuery library as well as the jQuery UI library. They are separate, because the jQuery UI in particular is rather large. So next up, we'll go into our codesnippets file and we'll need to also link to the version of the CSS file we downloaded from the jQuery UI site. So we're going to need to link to that peppergrinder.css we renamed right here. Back into my index file, I want to put this in the head section, and now we're ready to go with our jQuery UI component.

Now we are going to go back into my codesnippets and grab the function that actually makes the Datepicker work. So we'll copy this right here, we'll put it again right after we load up all the scripts, the bottom of the page, and now when we come over here, and we click on this field, it automatically pops up our beautiful calendar. Now if you remember from the jQuery UI site there's a lot of options that you can use when using this calendar. So if we click back here go back into the Datepicker, you'll see that there is a lot of different options, and if you View Source you can see how they accomplish the different options, so I'm going to show you a couple of the ones that I think are really important.

Right now, this is the default version of this Datepicker. If you go back into codesnippets, you can see that you can add additional functions, like for example, picking a specific date format or adding more than one month to the list. I'm going to go back into codesnippets and replace this function, and you'll see that now we have three months and we are asking for the date to be entered into the field in a specific format. So this is the kind of format that you would use if you wanted to use this date with something like mySQL, but you can make your date format to whatever you want.

Just check the documents when you format the date. You could choose from this list and take a look at the source code down there to customize the date to whatever you want. And thankfully, adding what normally would be a very complicated date pop-up to your forms is super simple with jQuery UI. So you might want to check out some of the other things in the library. The other library that you might want to check out is our own library of jQuery tutorials on the lynda.com web site. So see you next time and remember that if you can't wait to code on your next date, then you've probably got some time to View Source.

There are currently no FAQs about View Source.

Share a link to this course
Please wait... Please wait...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.
Upgrade now


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

join now

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed View Source.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Welcome to the redesigned course page.

We’ve moved some things around, and now you can



Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked