Tags

calendar-markedThis worked so well and I have not found a similar post.  I needed to block weekends and past dates on a datepicker for a registration form.  I happen to be using Ninja Forms, which uses the datepicker built into WordPress.  I added the following code to the selected page:

<script type="text/javascript">
    jQuery(function ($) {
        
            // 1 = monday, 2 = tuesday, 3 = wednesday, 4 = thursday,
            // 5=friday, 6 = saturday, 0=sunday
            var daysToDisable = [0, 6];
            $('#ninja_forms_field_69').datepicker({
                minDate:0,
                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>

 

The CSS & Javascript Toolbox plugin is a great way to add code to a selected page, post, or category.

Advertisements