5

I have looked at some of the answers here to this type of question but could not get them to work how I needed them to. I need to have my jQuery UI datepicker only allow Sundays in the past to be selected. Is this possible to do?

Thank you

2 Answers 2

14
// Enable Sunday only
$("#datepickerID").datepicker({
    dateFormat: 'dd-mm-yy',
    minDate: 1,
    beforeShowDay: enableSUNDAYS
});
// Custom function to enable SUNDAY only in jquery calender
function enableSUNDAYS(date) {
    var day = date.getDay();
    return [(day == 0), ''];
}
1
  • Hi, this method is not working for me, I get the following error: p.apply is not a function [Break On This Error] A);t=(this._getFirstDayOfMonth(m,g)-h+...()==N.getTime()&&g==a.selectedMonth&& on line 531 of jquery-ui file Any help? Aug 26, 2011 at 14:41
5

It's not exactly your situation, but contains what you need to know to do what you need to do:

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/base/jquery-ui.css"
        type="text/css" media="all" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js"
        type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {

            // 0 = monday, 1 = tuesday, 2 = wednesday, 3 = thursday,
            // 4 = friday, 5 = saturday, 6 = sunday

            var daysToDisable = [2, 4, 5];

            $('#<%= txtDate.ClientID %>').datepicker({
                beforeShowDay: disableSpecificWeekDays
            });

            function disableSpecificWeekDays(date) {
                var day = date.getDay();
                for (i = 0; i < daysToDisable.length; i++) {
                    if ($.inArray(day, daysToDisable) != -1) {
                        return [false];
                    }
                }
                return [true];
            }
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:TextBox ID="txtDate" runat="server"></asp:TextBox>
    </form>
</body>
</html>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.