Issue with Custom Script Throw statement

Hi Everyone,

I was writing a custom script and wanted to validate some data using some logics.

frappe.ui.form.on("Time Log","validate", function(frm) {

var a=new Date(frm.doc.from_time);
var b=new Date(frm.doc.to_time);

a=a.getDate();
b=b.getDate();

if (a!=b)
{ msgprint("You cannot create the Time Log across dates!"); 
throw "not allowed"; }
});

Everything is working fine except the throw "not allowed";
The moment control reaches here, save button get grey/disabled and at that time, I am not able to save the time log by changing the data.

Does, anybody have some idea about this?

Regards
Ruchin Sharma

@ruchin78, replace the throw for validated = false;

@max_morais_dmm
Sorry, I didn’t understand. I appreciate, if you can elaborate how to use it.

@ruchin78 the validate event listen for a global variable named validated so, you dont need throw anything, you only need define the variable as false

Hi @max_morais_dmm,

Its done!

Thanks a lot for your help and I salute to your knowledge.

Regards
Ruchin Sharma

1 Like

Thank you so much @ruchin78!

This topic was automatically closed after 21 hours. New replies are no longer allowed.