Validation script for custom forms

I have created new doctype in HR module. I am trying to create a script to validate two dates on my form. I would like the script to ensure that departure date is lower than the arrival date. Could anyone point me in the right direction in where and how to do this?


You can add the trigger on departure date as follows:

frappe.ui.form.on("DOCTYPE NAME", "departure_date", function(frm){
  date_diff = dateutil.get_diff(cur_frm.doc.departure_date, frm.doc.arrival_date)
  if(date_diff > 0){
	// code if depature date is greater than arrival date
	// code if depature date is lower than arrival date


Or you can check this validations on validate trigger, which will be called on save button click.

frappe.ui.form.on("DOCTYPE NAME", "validate", function(frm){
     // code to check if departure date is greater or lower than arrival date

Makarand Bauskar

1 Like