Sam B.
Sam B.

Reputation: 3033

jQuery DatePicker select only saturday

I want to set a datepicker from jquery ui to allow only saturday. This depends on another selected field so only one location needs to have this feature.

Before this I initialize them like this

$(".datepicker").datepicker();

all the date fields have the .datepicker class

the arrival date is changed to this if it's on that single location

$(".arrival-date").datepicker(
    {
        beforeShowDay: function(date){
            if(date.getDay() == 6){
                return [true];
            } else {
                return [false];
            }
        }
    }
);

it doesn't work even when I try it on the console directly.

Upvotes: 2

Views: 750

Answers (2)

Parth Raval
Parth Raval

Reputation: 4423

$(".datepicker").datepicker({
  numberOfMonths: 3,
  dateFormat: "m/d/yy",
  altField: "#altFormat",
  changeMonth: true,
  changeYear: true,
  altFormat: "yy-mm-dd",
  minDate: 0,
  beforeShowDay: function(date) {
    var day = date.getDay();
    return [day == 6, ''];
  }
});
#ui-datepicker-div {
  font-size: 12px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src='https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js'></script>
<link rel="stylesheet" type="text/css" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css"> Date Picker on input field: <input type="text" id="datepicker" class='datepicker' name="date1" /> <br/>

Upvotes: 2

Dylan KAS
Dylan KAS

Reputation: 5663

You could try this :

$( ".arrival-date" ).datepicker('option','beforeShowDay',function(date){
    var today = date.getDay();
    var result = [(date.getDay() == 6),'',(today == 'Sat' ) ? '': 'Not saturday'];
    return result;
});

Upvotes: 1

Related Questions