onSubmit client script is not working for date validation

Jesus Nava
Tera Guru

Hello experts, please I need your help, when users create a knopwledge article, there is a "valid to" field that automatically sets it for a year, I created an onChange client script that does not let the users add more than 365 days and it is workng fine, but I was asked to create an onSubmit script instead or a BR, so I went ahead and tried to create an onSUbmit client script but it is not working, here is the code:

JesusNava_0-1683926220455.png

but at the time I click "submit" adding more than a year, it gives me a javascript error,

JesusNava_1-1683926365551.png

 

what am I doing wrong? can you  help me out? 

2 ACCEPTED SOLUTIONS

Sandeep Rajput
Tera Patron
Tera Patron

@Jesus Nava Your client script is returning an error because on line number 3 you have used a variable newValue which isn't defined anywhere inside the script. You probably copied this code from an onChange script where newValue parameter is available in function argument. However, newValue isn't available inside an onSubmit script.

 

Try fetching the value data from an existing field on the form as follows.

 

 

g_form.getValue('field_name');//replace field name with the name of your field.

 

View solution in original post

Devender Kumar
Tera Guru
Tera Guru

Hi @Jesus Nava 

Please use something like this in your first two line of codes

var gdt = new Date(g_form.getValue('name_of_your_field'));
var current_date = new Date();

 

If this resolved your issue, then please don't forget to mark as correct or helpful.

 

Regards

Devender

View solution in original post

4 REPLIES 4

Sandeep Rajput
Tera Patron
Tera Patron

@Jesus Nava Your client script is returning an error because on line number 3 you have used a variable newValue which isn't defined anywhere inside the script. You probably copied this code from an onChange script where newValue parameter is available in function argument. However, newValue isn't available inside an onSubmit script.

 

Try fetching the value data from an existing field on the form as follows.

 

 

g_form.getValue('field_name');//replace field name with the name of your field.

 

Thank you it worked perfectly!

Devender Kumar
Tera Guru
Tera Guru

Hi @Jesus Nava 

Please use something like this in your first two line of codes

var gdt = new Date(g_form.getValue('name_of_your_field'));
var current_date = new Date();

 

If this resolved your issue, then please don't forget to mark as correct or helpful.

 

Regards

Devender

Thank you it worked perfectly!!