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

Question

Question

dynamic min value on date field in Forms

asked on July 14, 2017

I am working on jquery code for LF Forms where the minimum allowed date is dynamically set to another field's date (which is always in the future).  I am triggering these functions from a conditional statement earlier in the code.  The copying of the field to the new field at the bottom of the code works.  I've used this logic on another function that defaults to today's date and it works but when I am trying to set the min date from another field it does not.  

    function EffectiveDateMinEligible(){  
     //  alert('Part B Eligible Date Input for Min');
    var EligibleDate = $('.EligibleDate input').val();
 
    $('.SelectDate input').val(EligibleDate);
    $('.SelectDate input').attr('min',EligibleDate);
   


  };

Any help in where I've gone wrong is appreciated!

Terri

0 0

Answer

SELECTED ANSWER
replied on July 14, 2017 Show version history

Hi Terri,

The trick to setting the minimum date is the formatting. I'm pretty sure it has to be YYYY-MM-DD including leading zeroes where applicable.

I've included the code I use, which uses the current date, but you should be able to modify it to use a dynamic field once you get an idea of how the value has to be formatted.

  // Get date information
  var d = new Date();
  var dmy = [d.getDate(), (d.getMonth() + 1), d.getFullYear()];
  
  // Format date to add leading zeros where needed
  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
  $('#Field').attr('min',(dmy[2] + "-" + dmy[1] + "-" + dmy[0]));

 

2 0
replied on July 17, 2017

Thank you Jason!  I was able to get the code to work with mine.  I appreciate you taking the time to help.

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.