DZone
Web Dev Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Web Dev Zone > Disable Dates In Datepicker

Disable Dates In Datepicker

A tutorial on how we can disable some dates in a jQuery datepicker control.

Sibeesh Venu user avatar by
Sibeesh Venu
·
Nov. 17, 15 · Web Dev Zone · Tutorial
Like (10)
Save
Tweet
59.17K Views

Join the DZone community and get the full member experience.

Join For Free

In this post we will see how we can disable some dates in a jQuery datepicker control. We all worked in datepicker controls right? But in some situations we may need to add some validations like to restrict some dates in the picker so that user can not select those and move further. Here we are going to disable all the future Saturdays. I hope you will like this.

Using the Code

The first thing you need to do is including the needed files.

jQuery

jQuery UI

jQuery UI CSS

Once you are done adding the files, you need to add a text box in which we are going to implement the picker.

<input type="text" value="Select Date Here"/>

Now we will create an array which contains the list of dates we need to disable.

var disabledDates = ["2015-11-28","2015-11-14","2015-11-21"]


Next we will load the datepicker to our text box.

$('input').datepicker({
    beforeShowDay: function(date){
        var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
        return [ disabledDates.indexOf(string) == -1 ]
    }
});


Have you noticed that we are calling a function beforeShowDay, this is used to disable the dates. It will return false if the date exists in the disabledDates.

That’s all we have done it.

Please see the jsfiddle here: Disable Date In DatePicker

Output

Image title

Disable Dates In Datepicker

Conclusion

Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.

Your Turn. What Do You Think?

A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.

JQuery UI code style POST (HTTP) Blog CSS Overflow (software) Links Data structure

Published at DZone with permission of Sibeesh Venu, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Which Backend Frameworks Are Impacting Web App Development Immensely?
  • Purpose-Driven Microservice Design
  • Top 7 Features in Jakarta EE 10 Release
  • DZone's Article Submission Guidelines

Comments

Web Dev Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo