DZone
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
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Optimize Your Links For Print Using CSS: Show The URL
  • DataWeave Interview Question: Compare IDs From Two Arrays and Create a New Array
  • Stop Running Two Data Systems for One Agent Query
  • Programmatic Brand Extraction: Pulling Logos, Colors, and Assets from Any URL

Trending

  • Retesting Best Practices for Agile Teams: A Quick Guide to Bug Fix Verification
  • The Network Attach Problem Nobody Warns You About
  • The Vector Database Lie
  • Securing Everything: Mapping the Right Identity and Access Protocol (OIDC, OAuth2, and SAML) to the Right Identity
  1. DZone
  2. Data Engineering
  3. Data
  4. Disable Dates In Datepicker

Disable Dates In Datepicker

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

By 
Sibeesh Venu user avatar
Sibeesh Venu
·
Nov. 17, 15 · Tutorial
Likes (10)
Comment
Save
Tweet
Share
74.8K 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. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Optimize Your Links For Print Using CSS: Show The URL
  • DataWeave Interview Question: Compare IDs From Two Arrays and Create a New Array
  • Stop Running Two Data Systems for One Agent Query
  • Programmatic Brand Extraction: Pulling Logos, Colors, and Assets from Any URL

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook