Avoiding choosing holidays and weekend days on date questions

Mehr
3 Jahre 4 Monate her #117858 von samarta
samarta erstellte das Thema Avoiding choosing holidays and weekend days on date questions
Hi,


Is it possible to:

1 - include national holidays in the calendar?
2 - generate a error message if the responder chooses a weekend day?


Thanks in advance,

João Sá Marta

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
3 Jahre 4 Monate her #117859 von holch
holch antwortete auf das Thema: Avoiding choosing holidays and weekend days on date questions
I wouldn't say it is impossible, but I think it would involve a lot of work with Javascript and/or Expression Manager.

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
3 Jahre 4 Monate her - 3 Jahre 4 Monate her #117881 von tpartner
tpartner antwortete auf das Thema: Avoiding choosing holidays and weekend days on date questions
If you want to show all holidays and disable weekend days, you can modify the "beforeShowDay" option for the datepicker, looping through an array of the holidays.

Set up your survey to use JavaScript and place the following script in the source of the question. All holidays will be assigned a "holiday" class and weekend days (including holidays) will be disabled.
<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>

Add something like this to the end of template.css.
.ui-datepicker-calendar td.holiday a,
.ui-datepicker-calendar td.holiday span {
	background: none pink !important;
}





If you simply want to disable weekend days, you can use the built-in "noWeekends" function.
<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>

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Anhang:
Letzte Änderung: 3 Jahre 4 Monate her von tpartner.
Folgende Benutzer bedankten sich: Ben_V, samarta

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
3 Jahre 4 Monate her #117905 von samarta
samarta antwortete auf das Thema: Avoiding choosing holidays and weekend days on date questions
Hi,

Thank you very much, it works fine.

Only one remark:

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.


Once again , thank you very much.


-- João Sá Marta

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
3 Jahre 4 Monate her #117908 von samarta
samarta antwortete auf das Thema: Avoiding choosing holidays and weekend days on date questions
Hi,
I am not a JavaScript expert but I solved my last question:

Just put :

$(document).ready(function() {
$("button").click(function(){
.....
.....
});
});

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
3 Jahre 4 Monate her #117911 von tpartner
tpartner antwortete auf das Thema: Avoiding choosing holidays and weekend days on date questions
Can you activate a test survey for us to see?

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
3 Jahre 4 Monate her - 3 Jahre 4 Monate her #117931 von samarta
samarta antwortete auf das Thema: Avoiding choosing holidays and weekend days on date questions
Hi,

surveys.uc.pt/index.php/729839/lang-en

one holiday is 1/1/2015, partial translation from PT

I've made impossible to choose holidays also

-- João

Here is the code:

<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$("button").click(function(){
// Identify this question
var thisQuestion = $('#question{QID}');

// The holidays - format: [month, date, description]
holidays = [
[1, 1, 'Dia de Ano Novo'], [2, 16, 'Family Day'], [4, 3, 'Sexta Feira Santa'],
[4, 5, 'Domingo de Páscoa'], [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 and holidays 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]+', Não é possível selecionar dias de fim de semana']; // Weekend holiday
}
else {
returnedArr = [false, 'holiday', value[2]+', Cannot choose holidays']; // 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).datepicker( "show" );
});
});
</script>
Letzte Änderung: 3 Jahre 4 Monate her von samarta.

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
3 Jahre 4 Monate her #117934 von tpartner
tpartner antwortete auf das Thema: Avoiding choosing holidays and weekend days on date questions

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.


Change this line:
$('input[type="text"]', thisQuestion).datepicker('option', 'beforeShowDay', showHolidaysDisableWeekends).datepicker( "show" );

To this:
$('input[type="text"]', thisQuestion).datepicker('option', 'beforeShowDay', showHolidaysDisableWeekends);

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
1 Jahr 2 Monate her #154774 von terryaulenbach
terryaulenbach antwortete auf das Thema: Avoiding choosing holidays and weekend days on date questions
Hey, samarta. I am wondering if things have changed with v2.5x. I am using v2.56.1+161118 and unfortunately, this code is not working for me. No dates are being blocked or highlited. Could you please let me know if there is still a way to accomplish this? I would really like to block all days but Tues, Wed, & Thurs. Thanks!

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
1 Jahr 2 Monate her #154792 von tpartner
tpartner antwortete auf das Thema: Avoiding choosing holidays and weekend days on date questions
Version 2.5x uses the Bootstrap Datepicker widget so you can disable days with the "daysofweekdisabled" option - eonasdan.github.io/bootstrap-datetimepic.../#daysofweekdisabled

To disable all days except Tues, Wed and Thurs, place this script in the question source:

<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>

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
1 Jahr 2 Monate her #154794 von terryaulenbach
terryaulenbach antwortete auf das Thema: Avoiding choosing holidays and weekend days on date questions
Thank you, Tony! This is extremely helpful. I had actually meant to ask you and got lost in the thread :)

Terry

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
10 Monate 3 Wochen her #157798 von samarta
samarta antwortete auf das Thema: Avoiding choosing holidays and weekend days on date questions
Hi,

I am planning an LimeSurvey upgrade to 2.67, and I have done it on a test machine.



The script to Avoiding choosing holidays and weekend days on date questions is not working .


Can anybody give me some hints ?


Thanks in advance,


João

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
10 Monate 3 Wochen her #157810 von tpartner
tpartner antwortete auf das Thema: Avoiding choosing holidays and weekend days on date questions
A script like this will disable weekends and some holidays in the Bootstrap Datepicker (dates depend on your format setting):

<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>

Sample survey attached:

Dateianhang:

Dateiname: limesurvey...8-22.lss
Dateigröße:13 KB

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Anhang:

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
7 Monate 2 Wochen her #161049 von terryaulenbach
terryaulenbach antwortete auf das Thema: Avoiding choosing holidays and weekend days on date questions
Hi, Tony. I noticed that daysOfWeekDisabled continues to work when I switch to January 2018, but disabledDates seems to only work for the current year. Is that by design? Is there a way to have, say Jan. 1st disabled for every year rather than having to specify the year (e.g. '01-01-2017', '01-01-2018') and keep updating it each year?

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Mehr
7 Monate 2 Wochen her #161070 von tpartner
tpartner antwortete auf das Thema: Avoiding choosing holidays and weekend days on date questions
Yes, you could programmatically loop through future years and insert the fixed holidays. Something like this (for Canadian holidays):

<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>

Sample survey attached.

Dateianhang:

Dateiname: limesurvey...7277.lss
Dateigröße:13 KB

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Anhang:
Folgende Benutzer bedankten sich: samarta, terryaulenbach

Bitte Anmelden oder Registrieren um an der Konversation teilzunehmen.

Jetzt loslegen!

Melden Sie sich jetzt an, und erstellen Sie in wenigen Minuten Ihre erste Umfrage.

Account einrichten

Abonnieren Sie unseren Newsletter

Abonnieren Sie unseren Newsletter für alle Neuigkeiten rund um LimeSurvey
captcha