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

sorry - this is the first question I've posted out here.   How do I mark the response was the correct answer?


No Problem. You should be seeing the correct answer button near the response..You have to click on that.


Please let me know if you have any questions.


Great


Please see my last comment to reset the variable. You need to change that line as well in your code.



Please mark the correct/helpful answers.



Thanks,


Tanaji


I don't think we need to use variables in client side to set the Value..All you need is the name of the variable.


Hi Pradeep,


hope you can help pls.


I have a date variable in a catalog item that i want to put a validation on.


Date type is "date"



So Basically, user selects date and calendar pops up, they select the date. if the date selected is less than 5 working days then i want an error or alert to pop up.


I have tried modifying the above script but it's not working.



Are you able to help pls?




Thanks in advance