- Posts: 10
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Have survey submittable after a certain date?
- Darren
- Topic Author
- Offline
- New Member
Darren wrote: Once I figured out that the question should be on the last page, and not the first, it's working splendidly. Since there's no question to add the "This question is mandatory" warning, the popup might be a little confusing. I could add a text Q at the bottom stating that attempting to submit prior to X date will result in an error.
Semi-related, is it possible to perform "date math"...specifically, something like {EXPIRY-3} (which would show the date 3 days prior to the survey's expiration)?
Quoting myself because I realize I wasn't clear on this - I'd like to use date math on the relevance equation. This way I can have a "warning" message at the bottom when the survey is unsubmittable, and direct the user to click "Resume later". Thanks again!
- Deusdeorum
- Offline
- Senior Member
- Posts: 72
- Thank you received: 17
Darren wrote:
Deusdeorum wrote: DenisChenu´s answer is probably a better approach but here's a javascript solution that disables button on click with an alert.
Code:<script type="text/javascript" charset="utf-8"> $(document).ready(function() { var date_now = new Date(); var sub_date = new Date("2017-1-10"); if (date_now < sub_date) { $('#movesubmitbtn').click(function() { $(this).prop('disabled', true); alert("You cannot submit this survey until" + sub_date); }); } }); </script>
That's awesome, thanks! I combined it with {EXPIRY} and a little date math so now it won't be submittable until X days before expiration.
Please carefully test this before using it in production because I haven't.
- Darren
- Topic Author
- Offline
- New Member
- Posts: 10
- Thank you received: 0
So far the only problem I've found is that it doesn't seem to work on mobile (iPad/iPhone). It seems to bypass the JS and gives the standard "One or more questions have not been answered in a valid manner. You cannot proceed until these answers are valid." I've search the forum for javascript on mobile, but haven't found anything other than a question of whether JS can be disabled completely. Is there a trick that I'm missing?Deusdeorum wrote:
Please carefully test this before using it in production because I haven't.
- tpartner
- Offline
- LimeSurvey Community Team
- Posts: 10098
- Thank you received: 3589
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { var date_now = new Date(); var sub_date = new Date("2017-1-15"); if (date_now < sub_date) { $('#movesubmitbtn').click(function(e) { e.preventDefault(); alert("You cannot submit this survey until" + sub_date); return false; }); } }); </script>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
- Deusdeorum
- Offline
- Senior Member
- Posts: 72
- Thank you received: 17
tpartner wrote: Try this:
Code:<script type="text/javascript" charset="utf-8"> $(document).ready(function() { var date_now = new Date(); var sub_date = new Date("2017-1-15"); if (date_now < sub_date) { $('#movesubmitbtn').click(function(e) { e.preventDefault(); alert("You cannot submit this survey until" + sub_date); return false; }); } }); </script>
Hehe, I fucked up in Date("x-x-x") in first script, apparently "2017-1-15" is not a valid date (doh). Anyhow, this is working fine on iphone 6+7:
This is an array with condition on first sub-question in survey2. <script type="text/javascript" charset="utf-8"> $(document).ready(function() { var date_now = new Date(); var sub_date = new Date("2017-01-11"); if (date_now < sub_date) { $('#movesubmitbtn').on('click touch', function() { $(this).prop('disabled', true); alert("You cannot submit this survey until" + sub_date); }); } }); </script>