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
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 8 months ago #157810 by tpartner
A script like this will disable weekends and some holidays in the Bootstrap Datepicker (dates depend on your format setting):

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:

File Attachment:

File Name: limesurvey...8-22.lss
File Size:13 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
6 years 4 months ago #161049 by terryaulenbach
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
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 4 months ago #161070 by tpartner
Yes, you could programmatically loop through future years and insert the fixed holidays. Something like this (for Canadian holidays):

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.

File Attachment:

File Name: limesurvey...7277.lss
File Size:13 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: samarta, terryaulenbach
The topic has been locked.
More
6 years 4 months ago #161130 by terryaulenbach
Thanks again, Tony. This worked great after I fixed my typos :)
The topic has been locked.
More
5 years 8 months ago #172684 by terryaulenbach
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?

The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 8 months ago #172701 by tpartner
Are there any JavaScript errors in the console?

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.
More
5 years 8 months ago #172724 by terryaulenbach
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
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 8 months ago #172726 by tpartner
Does the survey behave properly if you remove the date question JavaScript?

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.
The topic has been locked.
More
5 years 8 months ago #172727 by terryaulenbach
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
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 8 months ago #172733 by tpartner
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 :) )

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
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 8 months ago #172734 by holch
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
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 8 months ago #172735 by tpartner
"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.

Lime-years ahead

Online-surveys for every purse and purpose