Try ERPNext Buy Support Partners Foundation

Allow on submit with validation event

While action status is “Update” why “validate” and “before_save” events not fire ?
Is there an important reason I can’t understand?

Thanks.

_f.Frm.prototype._save = function(save_action, callback, btn, on_error, resolve, reject) {
var me = this;
if(!save_action) save_action = "Save";
this.validate_form_action(save_action, resolve);

if((!this.meta.in_dialog || this.in_form) && !this.meta.istable) {
	frappe.utils.scroll_to(0);
}
var after_save = function(r) {
	if(!r.exc) {
		if (["Save", "Update", "Amend"].indexOf(save_action)!==-1) {
			frappe.utils.play_sound("click");
		}

		me.script_manager.trigger("after_save");
		me.refresh();
	} else {
		if(on_error) {
			on_error();
			reject();
		}
	}
	callback && callback(r);
	resolve();
};

var fail = () => {
	btn && $(btn).prop("disabled", false);
	if(on_error) {
		on_error();
		reject();
	}
};
  // Why only update ?
if(save_action != "Update") {
	// validate
	frappe.validated = true;
	frappe.run_serially([
		() => this.script_manager.trigger("validate"),
		() => this.script_manager.trigger("before_save"),
		() => {
			if(!frappe.validated) {
				fail();
				return;
			}

			frappe.ui.form.save(me, save_action, after_save, btn);
		}
	]).catch(fail);
} else {
	frappe.ui.form.save(me, save_action, after_save, btn);
}
};