You are viewing limited content. For full access, please sign in.

Question

Question

Is there a way to set a date range limit on Forms?

asked on August 4, 2017

I am trying to set a rule in which if a form is not submitted within a specific time range for trip request, a warning would come out stating you cannot submit this form because you are not meeting the requirements for the deadline.  We have a policy that a trip request form should be submitted 3 weeks prior to trip but we have some users that submit the form on the week of the trip or the day of the trip and then asking why a bus wasn't available for their trip.  

0 0

Answer

SELECTED ANSWER
replied on August 4, 2017 Show version history

Do you mean just setting a limit on the field, and preventing it from submitting if it doesn't fall within the range? If so, you can use the following:

// Get date information
  var d = new Date();
  
  // Get past date information
  d.setDate(d.getDate() + 21);
  dmy = [d.getDate(), (d.getMonth() + 1), d.getFullYear()];
  
  // Format date to add leading zeros where needed
  // Necessary for this to work!
  for (var n = 0; n < 2; n++){
    if (dmy[n].toString().length < 2){
      dmy[n] = "0" + dmy[n];
    }
  }

  // Set the min date value for the effective date calendar
  $('#YourField').attr('min',(dmy[2] + "-" + dmy[1] + "-" + dmy[0]));
  

Just replace #YourField either with whatever unique identifier you have for the date input field (#Field13, .dateField, etc.).

If you want to set a max range too, you can do with the same kind of process, just add instead of subtract, then apply the value as the 'max' attribute.

So, basically what it is doing is taking today's date, adding 21 days, then setting that as the earliest possible value in the calendar pop-up. If they try manually typing a date out of that range, a validation error will pop up. The default validation message shows the valid range, but depending on what version of Forms your using, that can be customized that to say something like "Requests must be made at least 3 weeks in advance" using the Error Messages section.

1 0
replied on August 4, 2017

Thank you so much!

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.