- Posts: 35
- Thank you received: 1
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify this question var thisQuestion = $('#question{QID}'); // The holidays - format: [month, date, description] holidays = [ [1, 1, 'News Years day'], [2, 16, 'Family Day'], [4, 3, 'Good Friday'], [5, 18, 'Victoria Day'], [7, 1, 'Canada Day'], [9, 7, 'Labour Day'], [10, 12, 'Thanksgiving'], [12, 25, 'Christmas'], [12, 26, 'Boxing Day'] ]; // A function to show holidays and disable weekend days in a datepicker function showHolidaysDisableWeekends(date) { var thisMonth = date.getMonth(); var thisDate = date.getDate(); var thisDay = date.getDay(); var returnedArr = [true, '']; // Normal day // Loop through the holidays $(holidays).each(function(i, value) { if (thisMonth == value[0] - 1 && thisDate == value[1]) { if(thisDay == 0 || thisDay == 6) { returnedArr = [false, 'holiday', value[2]+', cannot choose a weekend day']; // Weekend holiday } else { returnedArr = [true, 'holiday', value[2]]; // Weekday holiday } return false; // Exit the loop } else if (thisDay == 0 || thisDay == 6) { returnedArr = [false, '', 'Cannot choose a weekend day']; // Weekend day } }); return returnedArr; } // Apply the new "beforeShowDay" option $('input[type="text"]', thisQuestion).datepicker('option', 'beforeShowDay', showHolidaysDisableWeekends); }); </script>
.ui-datepicker-calendar td.holiday a, .ui-datepicker-calendar td.holiday span { background: none pink !important; }
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify this question var thisQuestion = $('#question{QID}'); // No weekends $('input[type="text"]', thisQuestion).datepicker('option', 'beforeShowDay', $.datepicker.noWeekends); }); </script>
When I open the survey the calendar shows up, and not only one cliks on the button with the 3 dots of the date question.
$('input[type="text"]', thisQuestion).datepicker('option', 'beforeShowDay', showHolidaysDisableWeekends).datepicker( "show" );
$('input[type="text"]', thisQuestion).datepicker('option', 'beforeShowDay', showHolidaysDisableWeekends);
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // Disable days of week $('#answer{SGQ}_datetimepicker').data('DateTimePicker').daysOfWeekDisabled([0,1,5,6]); }); </script>
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // Disable weekends $('#answer{SGQ}_datetimepicker').data('DateTimePicker').daysOfWeekDisabled([0,6]); // Disable holidays $('#answer{SGQ}_datetimepicker').data('DateTimePicker').disabledDates(['04-09-2017', '09-10-2017', '25-12-2017', '26-12-2017', '01-01-2018']); }); </script>
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // Disable weekends $('#answer{SGQ}_datetimepicker').data('DateTimePicker').daysOfWeekDisabled([0,6]); // Disable holidays var holidays = ['19-02-2018', '30-03-2018', '21-05-2018', '30-09-2018', '08-10-2018'] // Variable holidays var futureYears = 3; // Number of years to handle future fixed holidays var thisYear = new Date().getFullYear(); for (i = 0; i < (futureYears+1); i++) { holidays.push('01-01-'+(thisYear+i)); // New Years holidays.push('25-12-'+(thisYear+i)); // Christmas holidays.push('26-12-'+(thisYear+i)); // Boxing Day } $('#answer{SGQ}_datetimepicker').data('DateTimePicker').disabledDates(holidays); }); </script>