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
  • Darren's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 3 months ago #146887 by Darren

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!
The topic has been locked.
More
7 years 3 months ago #146894 by Deusdeorum
Replied by Deusdeorum on topic Have survey submittable after a certain date?

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.
The topic has been locked.
  • Darren
  • Darren's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 3 months ago #146932 by Darren

Deusdeorum wrote:
Please carefully test this before using it in production because I haven't.

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?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 3 months ago - 7 years 3 months ago #146945 by tpartner
Replied by tpartner on topic Have survey submittable after a certain date?
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>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 7 years 3 months ago by tpartner.
The topic has been locked.
More
7 years 3 months ago - 7 years 3 months ago #146947 by Deusdeorum
Replied by Deusdeorum on topic Have survey submittable after a certain date?

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:

Code:
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>
Last edit: 7 years 3 months ago by Deusdeorum.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose