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

Question

Question

Fields type DATE restrict

asked on May 23, 2023 Show version history

Hello I have 2 fields type date but I would like that my firs field date, I can put any date and in my second field date , the minimum date is the one you select in the first date field

 

I have this code that i take of this page and URL but it is not function for my help me where is de error

https://answers.laserfiche.com/questions/109445/How-to-restrict-date-picker-selection-based-on-the-entry-in-another-date-field#109448

 

I use the ID's of the Fields and the format is DD/MM/YY

 

$(document).ready(function () {
  $('#q5').on('change', function() { 
    var datearray = $('#q5 input').val().split("-");
    var montharray = ["Jan", "Feb", "Mar","Apr", "May", "Jun","Jul", "Aug", "Sep","Oct", "Nov", "Dec"];
    var year = "20" + datearray[2];
    var month = montharray.indexOf(datearray[1])+1;
    var day = datearray[0];
    var minDate = (year +"-"+ month +"-"+ day);
    $('#q6 input').attr('min',minDate); 
  });
});

 

0001.png
0002.png
0001.png (8.33 KB)
0002.png (11.73 KB)
0 0

Replies

replied on May 23, 2023 Show version history

We have our Absence Request form setup this way.

The FROM Date is not restricted, but the TO Date can't be any date before the FROM Date.

Here's how we have that setup (this is for Civil Service employees, which is why you see "CS"):

These fields are in a table, so we use have this Class on the table: MincsTable

On the FROM Date, we use the Class: minCSfrom

On the TO Date, we use the Class: minCSto

And then we use this Javascript (this was written in v10 and tested in v11 Classic Designer):

$(document).ready (function () {

 $('.MincsTable').on('change','.minCSfrom input', function () {   

    $('.MincsTable.cf-table-block tbody tr').each(function() {
     
      var theCSFromDate = $(this).find('.minCSfrom div.cf-date-field-date input');
      var theCSToDate = $(this).find('.minCSto div.cf-date-field-date input');
      var theCSDate = new Date(theCSFromDate.val());
   		
      var year = theCSDate.getFullYear();                         // YYYY
      var month = ("0" + (theCSDate.getMonth() + 1)).slice(-2);    // MM
      var day = ("0" + theCSDate.getDate()).slice(-2);            // DD
      var minDate = (year +"-"+ month +"-"+ day); // Results in "YYYY-MM-DD" for today's date 
      
      
      $(theCSToDate).attr('min', minDate);

      

    });
  });
  });

I hope that helps!

3 0
replied on May 23, 2023

Hi Carlos,

If you're able to use the latest version of the modern Forms designer, you can set up a field rule to do this for you without any code. I have quite a few that look like this:

Once the first date field is filled out, this rule forces the second date field to be after the first one. But, this is only in the latest version of Forms (I think) in the modern designer. If you have a bunch of CSS and Javascript already in your form, it might be tough to switch to the modern designer.

3 0
replied on May 23, 2023

Thanks for your answers but I need a CODE JS because I have too much CSS AND JS en my form

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

Sign in to reply to this post.