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
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
def set_name_in_children(self):
# Set name for any new children
for d in self.get_all_children():
if not d.name:
set_new_name(d)
def validate_update_after_submit(self):
if self.flags.ignore_validate_update_after_submit:
return
self._validate_update_after_submit()
for d in self.get_all_children():
if d.is_new() and self.meta.get_field(d.parentfield).allow_on_submit:
# in case of a new row, don't validate allow on submit, if table is allow on submit
continue
d._validate_update_after_submit()
# TODO check only allowed values are updated
frappe and erpnext have a hooks.py that list events but these are not limited to client-side javascript events that you seek
"parents": [{"label": "Material Request", "route": "material-requests"}],
},
},
{"from_route": "/project", "to_route": "Project"},
{"from_route": "/tasks", "to_route": "Task"},
]
standard_portal_menu_items = [
{"title": "Projects", "route": "/project", "reference_doctype": "Project"},
{
"title": "Request for Quotations",
"route": "/rfq",
"reference_doctype": "Request for Quotation",
"role": "Supplier",
},
{
"title": "Supplier Quotation",
"route": "/supplier-quotations",
"reference_doctype": "Supplier Quotation",
"role": "Supplier",
},
"Address": "frappe.contacts.address_and_contact.get_permission_query_conditions_for_address",
"Communication": "frappe.core.doctype.communication.communication.get_permission_query_conditions_for_communication",
"Workflow Action": "frappe.workflow.doctype.workflow_action.workflow_action.get_permission_query_conditions",
"Prepared Report": "frappe.core.doctype.prepared_report.prepared_report.get_permission_query_condition",
}
has_permission = {
"Event": "frappe.desk.doctype.event.event.has_permission",
"ToDo": "frappe.desk.doctype.todo.todo.has_permission",
"User": "frappe.core.doctype.user.user.has_permission",
"Note": "frappe.desk.doctype.note.note.has_permission",
"Dashboard Chart": "frappe.desk.doctype.dashboard_chart.dashboard_chart.has_permission",
"Number Card": "frappe.desk.doctype.number_card.number_card.has_permission",
"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",
"File": "frappe.core.doctype.file.file.has_permission",
"Prepared Report": "frappe.core.doctype.prepared_report.prepared_report.has_permission",
}
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
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",
"before_validate": "Before Validate",
"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",
2 Likes