- Client Script- Compare a field date with current time

prabhmeet
Giga Expert

Hi,

My task is that on Change request form, Planned start date field should be 24 hours ahead of Current time.

I need to write a client Script for this.

Below mentioned is my script, if I put in the wrong date, error message comes up but goes away and does not stays on the form screen. Can anyone help with why it is happening?

 

function onSubmit(){
//Type appropriate comment here, and begin script below


var start = g_form.getValue('start_date');
var today = new Date();
today.setDate(today.getDate());
if (start.toString() <= today.toString()){
g_form.addErrorMessage("Planned Start Date cannot be less than 24 hrs ahead in future.");
}
}

1 ACCEPTED SOLUTION

sachin_namjoshi
Kilo Patron
Kilo Patron

Please modify your code like below

 

function onSubmit(){
//Type appropriate comment here, and begin script below


var start = g_form.getValue('start_date');
var today = new Date();
today.setDate(today.getDate());
if (start.toString() <= today.toString()){
g_form.addErrorMessage("Planned Start Date cannot be less than 24 hrs ahead in future.");

return false;
}
}

 

Regards,

Sachin

View solution in original post

5 REPLIES 5

sachin_namjoshi
Kilo Patron
Kilo Patron

Please modify your code like below

 

function onSubmit(){
//Type appropriate comment here, and begin script below


var start = g_form.getValue('start_date');
var today = new Date();
today.setDate(today.getDate());
if (start.toString() <= today.toString()){
g_form.addErrorMessage("Planned Start Date cannot be less than 24 hrs ahead in future.");

return false;
}
}

 

Regards,

Sachin

thanks it's working . Can you explain also why writing this return false was necessary?

siva_
Giga Guru

To abort the form submission , we have to return false from the on submit client script else it will do the processing in the code and proceed with the form submission

Thanks,

Siva

Returning false will abort the form submission