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.
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.
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.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.