How do you prevent users from selecting a date in the past?

ngriffiths
Mega Expert

We have a requirement to capture an effective date on a record producer and I have currently built a Date/Time variable that will allow us to do so.   Now with that being said, the rest of the requirement is to prevent users from selecting a date/time in the past.

For example, today is 1/14/2016, therefore the user should NOT be able to select 1/10/2016 as a possible date.  

Essentially, we want any date leading up to the current date/time to be read only.   Is this a possibility and if so how do we go about it?   I am not a programmer, so if there is a script involved, which I am positive there is, it would be much appreciated if you can help with that as well.

Thanks!

Niccole

1 ACCEPTED SOLUTION

According to the SNow wiki article, the flash method is not supported by the Service Catalog.   Thus that is prob why no matter what I am changing it to, it still is failing.   Not a huge deal, it would have been nice to have the field flash a color, but the field is mandatory and clearing the value will force them to select a date before they can submit the request.



I very much appreciate all your help!



Here is the final script for anyone who is curious:



Catalog Client Script


Applies to: A Catalog Item


Type: onChange



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


     


      if (isLoading || newValue == '') {


             


              return;


             


      }


     


     


      var dt = getDateFromFormat(newValue, g_user_date_time_format);


     


      var rightNow = new Date();


     


      if (dt < rightNow) {


             


              alert('The date value cannot be before the current date and time. Please correct.');


              g_form.clearValue("effective_date");


     


      }


     


}


View solution in original post

14 REPLIES 14

did you add the g_form at the start of that line?


-Anurag

Yep.   This is the whole script:



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


     


      if (isLoading || newValue == '') {


             


              return;


             


      }


     


     


      var dt = getDateFromFormat(newValue, g_user_date_time_format);


     


      var rightNow = new Date();


     


      if (dt < rightNow) {


             


              alert('The date value cannot be before the current date and time. Please correct.');


              g_form.clearValue(effective_date);


              g_form.flash("effective_date", "#FFFF00", 5);


                             


      }


     


}


g_form.clearValue('effective_date');



i think you missed the ''


-Anurag

So that worked for clearing the form, but the flash will not work.



I just tried



g_form.flash("effective_date", yellow, 2);



and that still didn't work


According to the SNow wiki article, the flash method is not supported by the Service Catalog.   Thus that is prob why no matter what I am changing it to, it still is failing.   Not a huge deal, it would have been nice to have the field flash a color, but the field is mandatory and clearing the value will force them to select a date before they can submit the request.



I very much appreciate all your help!



Here is the final script for anyone who is curious:



Catalog Client Script


Applies to: A Catalog Item


Type: onChange



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


     


      if (isLoading || newValue == '') {


             


              return;


             


      }


     


     


      var dt = getDateFromFormat(newValue, g_user_date_time_format);


     


      var rightNow = new Date();


     


      if (dt < rightNow) {


             


              alert('The date value cannot be before the current date and time. Please correct.');


              g_form.clearValue("effective_date");


     


      }


     


}