- Posts: 10109
- Thank you received: 3595
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Avoiding choosing holidays and weekend days on date questions
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
6 years 8 months ago #157810
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic 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):
Sample survey attached:
Code:
<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:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The topic has been locked.
- terryaulenbach
- Offline
- Junior Member
Less
More
- Posts: 37
- Thank you received: 1
6 years 4 months ago #161049
by terryaulenbach
Replied by terryaulenbach on topic 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?
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
6 years 4 months ago #161070
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic 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):
Sample survey attached.
Code:
<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.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The following user(s) said Thank You: samarta, terryaulenbach
The topic has been locked.
- terryaulenbach
- Offline
- Junior Member
Less
More
- Posts: 37
- Thank you received: 1
6 years 4 months ago #161130
by terryaulenbach
Replied by terryaulenbach on topic Avoiding choosing holidays and weekend days on date questions
Thanks again, Tony. This worked great after I fixed my typos
The topic has been locked.
- terryaulenbach
- Offline
- Junior Member
Less
More
- Posts: 37
- Thank you received: 1
5 years 8 months ago #172684
by terryaulenbach
Replied by terryaulenbach on topic Avoiding choosing holidays and weekend days on date questions
Hey, Tony. This code has been working great for us... until we upgraded to 3.12 last week. Then something weird started happening. Although it appears that surveys are being submitted with all data intact, rather than loading the end URL after a submit, the page is being reloaded with all the answers missing. So to the end user it looks like they just lost everything. When I do a "Check logic" on the 2 date questions (only one or the other comes up based on certain logic) I get what you see in the attachment. If you need to see the actual survey is there a way I can PM you the URL?
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
5 years 8 months ago #172701
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Avoiding choosing holidays and weekend days on date questions
Are there any JavaScript errors in the console?
Does the survey submit correctly if you remove the JavaScript from the date questions?
Does the survey submit correctly if you remove the JavaScript from the date questions?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- terryaulenbach
- Offline
- Junior Member
Less
More
- Posts: 37
- Thank you received: 1
5 years 8 months ago #172724
by terryaulenbach
Replied by terryaulenbach on topic Avoiding choosing holidays and weekend days on date questions
There is something that pops up in the console upon submit:
VM392 pjax.min.js:1 Uncaught TypeError: Cannot read property 'match' of null
at Pjax.loadContent (VM392 pjax.min.js:1)
at Pjax.<anonymous> (VM392 pjax.min.js:1)
at XMLHttpRequest.request.onreadystatechange (VM392 pjax.min.js:1)
loadContent @ VM392 pjax.min.js:1
(anonymous) @ VM392 pjax.min.js:1
request.onreadystatechange @ VM392 pjax.min.js:1
XMLHttpRequest.send (async)
module.exports @ VM392 pjax.min.js:1
loadUrl @ VM392 pjax.min.js:1
(anonymous) @ VM392 pjax.min.js:1
(anonymous) @ VM392 pjax.min.js:1
Navigated to surveys.acadiau.ca/index.php/XXXXX (survey ID blocked out)
jquery-migrate-3.0.0.min.js:2 JQMIGRATE: Migrate is installed, version 3.0.0
VM392 pjax.min.js:1 Uncaught TypeError: Cannot read property 'match' of null
at Pjax.loadContent (VM392 pjax.min.js:1)
at Pjax.<anonymous> (VM392 pjax.min.js:1)
at XMLHttpRequest.request.onreadystatechange (VM392 pjax.min.js:1)
loadContent @ VM392 pjax.min.js:1
(anonymous) @ VM392 pjax.min.js:1
request.onreadystatechange @ VM392 pjax.min.js:1
XMLHttpRequest.send (async)
module.exports @ VM392 pjax.min.js:1
loadUrl @ VM392 pjax.min.js:1
(anonymous) @ VM392 pjax.min.js:1
(anonymous) @ VM392 pjax.min.js:1
Navigated to surveys.acadiau.ca/index.php/XXXXX (survey ID blocked out)
jquery-migrate-3.0.0.min.js:2 JQMIGRATE: Migrate is installed, version 3.0.0
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
5 years 8 months ago #172726
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Avoiding choosing holidays and weekend days on date questions
Does the survey behave properly if you remove the date question JavaScript?
Try disabling AJAX mode in the theme options.
Try disabling AJAX mode in the theme options.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The topic has been locked.
- terryaulenbach
- Offline
- Junior Member
Less
More
- Posts: 37
- Thank you received: 1
5 years 8 months ago #172727
by terryaulenbach
Replied by terryaulenbach on topic Avoiding choosing holidays and weekend days on date questions
Tony, once again you have saved the day. Disabling Ajax in the theme settings has fixed the problem. Coincidentally I am visiting my brother in Ajax, Ontario tonight Can you tell me why Ajax was causing this issue?
Terry
Terry
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
5 years 8 months ago #172733
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Avoiding choosing holidays and weekend days on date questions
No, I can't say exactly but the pjax errors indicate a problem with loading the page via AJAX.
(those of us from the Ottawa area consider Ajax to be Toronto )
(those of us from the Ottawa area consider Ajax to be Toronto )
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- holch
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 11660
- Thank you received: 2742
5 years 8 months ago #172734
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on topic Avoiding choosing holidays and weekend days on date questions
So Canadians are so crazy about Ajax that they built a whole city in its honor????
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
5 years 8 months ago #172735
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Avoiding choosing holidays and weekend days on date questions
"City" may be over-stating it.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.