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

Question

Question

how to set Only exect Today and future Date in table date fields.

asked on January 6, 2018

Hi,

I want to set table date fields to accept only future date and today date. i have applied on below mentioned Code but this code only working on first row of table date field, other adding rows its not working.  below screenshot for ref:

Please suggest the modify code to resolve this problem. 

 

Code: 

$(document).ready(function(){
 
   var todaysDate = new Date(); // Gets today's date
    // Max date attribute is in "YYYY-MM-DD".  Need to format today's date accordingly
   var year = todaysDate.getFullYear();                        // YYYY
   var month = ("0" + (todaysDate.getMonth() + 1)).slice(-2);  // MM
   var day = ("0" + todaysDate.getDate()).slice(-2);           // DD
   var minDate = (year +"-"+ month +"-"+ day); // Results in "YYYY-MM-DD" for today's date 
   // Now to set the max date value for the calendar to be today's date
   $('.calendarDate input').attr('min',minDate);
});

 

Table Row:1

 

Table Row 2:   future date not hiding on second row.

 

0 0

Replies

replied on January 7, 2018

Hi Sumeet,

Check that you set the CSS class, on the advanced tab, to 'calendarDate' on your second date field.

0 0
replied on January 7, 2018

hi Andrew, 

 

It's table , Rows can be added as per requirement. CSS 'CalendarDate' applied on First row only. other added rows don't have calendarDate class.

 

thanks

Sumeet

0 0
replied on January 8, 2018

Hi Sumeet,

You need to reapply the attribute to all relevant inputs whenever the "add" link is clicked to add a new row to the table. Try the following Javascript:

$(document).ready(function(){
 
   var todaysDate = new Date(); // Gets today's date
    // Max date attribute is in "YYYY-MM-DD".  Need to format today's date accordingly
   var year = todaysDate.getFullYear();                        // YYYY
   var month = ("0" + (todaysDate.getMonth() + 1)).slice(-2);  // MM
   var day = ("0" + todaysDate.getDate()).slice(-2);           // DD
   var minDate = (year +"-"+ month +"-"+ day); // Results in "YYYY-MM-DD" for today's date 
   // Now to set the max date value for the calendar to be today's date
   $('.calendarDate input').attr('min',minDate);
   $(document).on('click','.cf-table-add-row',function() { $('.calendarDate input').attr('min',minDate); });
});
0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.