need catalog variable date to validate it is in future

karendk
Kilo Explorer

I've seen this in the community where this is working for others, but it's not working for me.   What do I have wrong?   I get no error message.   It's just ignored.

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

if(newValue != '')
{
var reqDate = new Date(getDateFromFormat(newValue, g_user_date_format));
var today = new Date();

if(reqDate.getTime() <= today.getTime()) {

alert('Date must not be in the past.');
  g_form.setValue('sDate', '');
}
}
}

1 ACCEPTED SOLUTION

Tanaji Patil
Tera Guru

Hi Karen,



You are just comparing the time. You should first compare date and then time. Or both at the same time.


Try with the below shown code-



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


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


  return;


  }



// if(newValue != '') don't need this as you already have checked above


// {


  var reqDate = new Date(newValue);


  var today = new Date();


  if(reqDate <= today){


  alert('Date must not be in the past.');


  g_form.setValue('closed_at', '');


  }


// }


}



Thanks,


Tanaji


View solution in original post

16 REPLIES 16

Hi Tanaji,

How do you set the default for a couple minutes past when the form loads? Can we do that within the same script?

Thanks,

Mike

David Stutter
Tera Guru

var reqDate = new Date(getDateFromFormat(newValue, g_user_date_time_format));