Nimrod
March 30, 2018, 12:55am
#1
Every now and then, I find myself asking which client-side event I should hook into for my javascript functions. And every time I check for a list of these events that are available to hook into, I can’t find a complete list.
Is there such a list somewhere?
1 Like
What I can glean from my learning survey -
The user frappe runs asyncio_posix.py that I figure is the event loop process that directs the event and callback mechanism.
For DocType Events the only list I have seen are documented here
https://frappe.io/docs/user/en/tutorial/controllers
https://frappe.io/docs/user/en/guides/app-development/executing-code-on-doctype-events
Apart from that there’s the code itself where events have say on_, before_ or after_* that give clues to when and what action event they answer to
@whitelist.__func__
def _cancel(self):
"""Cancel the document. Sets `docstatus` = 2, then saves."""
self.docstatus = 2
self.save()
@whitelist.__func__
def submit(self):
"""Submit the document. Sets `docstatus` = 1, then saves."""
self._submit()
@whitelist.__func__
def cancel(self):
"""Cancel the document. Sets `docstatus` = 2, then saves."""
self._cancel()
def delete(self):
"""Delete document."""
frappe.delete_doc(self.doctype, self.name, flags=self.flags)
def run_before_save_methods(self):
frappe and erpnext have a hooks.py that list events but these are not limited to client-side javascript events that you seek
"Patient Appointment": "erpnext.healthcare.web_form.patient_appointments.patient_appointments.has_website_permission",
"Patient": "erpnext.healthcare.web_form.personal_details.personal_details.has_website_permission"
}
dump_report_map = "erpnext.startup.report_data_map.data_map"
before_tests = "erpnext.setup.utils.before_tests"
standard_queries = {
"Customer": "erpnext.selling.doctype.customer.customer.get_customer_list"
}
doc_events = {
"Stock Entry": {
"on_submit": "erpnext.stock.doctype.material_request.material_request.update_completed_and_requested_qty",
"on_cancel": "erpnext.stock.doctype.material_request.material_request.update_completed_and_requested_qty"
},
"User": {
"after_insert": "frappe.contacts.doctype.contact.contact.update_contact",
"validate": "erpnext.hr.doctype.employee.employee.validate_employee_role",
"on_update": ["erpnext.hr.doctype.employee.employee.update_user_permissions",
"Kanban Board": "frappe.desk.doctype.kanban_board.kanban_board.has_permission",
"Contact": "frappe.contacts.address_and_contact.has_permission",
"Address": "frappe.contacts.address_and_contact.has_permission",
"Communication": "frappe.core.doctype.communication.communication.has_permission",
"Workflow Action": "frappe.workflow.doctype.workflow_action.workflow_action.has_permission"
}
has_website_permission = {
"Address": "frappe.contacts.doctype.address.address.has_website_permission"
}
standard_queries = {
"User": "frappe.core.doctype.user.user.user_query"
}
doc_events = {
"*": {
"on_update": [
"frappe.desk.notifications.clear_doctype_notifications",
"frappe.core.doctype.activity_log.feed.update_feed",
"frappe.workflow.doctype.workflow_action.workflow_action.process_workflow_actions"
edit: here are some code examples that lists triggers
This documents events from a hooks view https://frappe.io/docs/user/en/guides/basics/hooks
4 Likes
Nimrod
April 6, 2018, 5:33pm
#3
Thanks. I guess this is the best reference for now.
vijaywm
September 18, 2018, 6:21am
#4
Can attach to standard doctype events using custom_<event_name> as shown in example above.
Have seen these events scattered in code… frappe and erpnext
refresh
onload_post_render
before_load
onload
validate
Can see these events triggered in form.js
before_save
before_submit
on_submit
after_save
before_cancel
after_cancel
3 Likes
clarkej
January 23, 2020, 2:06pm
#5
For additional reference, note also this Server Script DocType feature introduced in V12…!
A Server Script lets you dynamically define a Python Script that is executed on the server on a document event or API
Here’s the documentation and the events it supports:
import frappe
# this is a separate file since it is imported in frappe.model.document
# to avoid circular imports
EVENT_MAP = {
'before_insert': 'Before Insert',
'after_insert': 'After Insert',
'validate': 'Before Save',
'on_update': 'After Save',
'before_submit': 'Before Submit',
'on_submit': 'After Submit',
'before_cancel': 'Before Cancel',
'on_cancel': 'After Cancel',
'on_trash': 'Before Delete',
'after_delete': 'After Delete',
2 Likes
Check the following links:
4 Likes