kintone.events.on().
Registering event handlers
kintone.events.on(type, handler)
Binds a handler function to one or more event types. Call this at the top level of your customization script so the handler is registered synchronously when the script loads.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
type | String or Array of strings | Yes | The event type or an array of event types to listen for. |
handler | Function | Yes | The function to call when the event fires. Receives the event object as its only argument. |
Basic usage
Registering the same handler for multiple events
Pass an array of event type strings to bind one handler to several events at once:Removing event handlers
kintone.events.off(type, handler)
Unbinds a previously registered handler. Handlers are never overwritten — they accumulate. Use kintone.events.off() to remove a handler before registering a replacement.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
type | String or Array of strings | No | The event type(s) to target. Omit to remove handlers for all event types. |
handler | Function | No | The specific handler to remove. Omit to remove all handlers for the given type. |
true if at least one handler was removed; false if no matching handler was found.
The event object
Every handler receives an event object as its argument. The properties available depend on the event type, but the following are common across most events:| Property | Type | Description |
|---|---|---|
type | String | The event type that fired, e.g. 'app.record.index.show'. |
appId | Number | The ID of the current app. |
record | Object | The current record’s field data (available on record create, edit, and detail events). |
records | Array or Object | The records in the current list view (available on record list events). |
viewId | Number | The ID of the current view (record list events). |
viewName | String | The name of the current view (record list events). |
viewType | String | The view type: 'list', 'calendar', or 'custom'. |
offset | Number | The list offset for the current page (list and custom views). |
size | Number | The number of records on the current page. |
error | String | Set this property to display an error message at the top of the screen and cancel the current operation. |
url | String | Set this property on save-success events to redirect to a different URL after saving. |
Record list onload event object example
Theapp.record.index.show event object includes these key properties:
Modifying behavior via the event object
For many event types, you can change what Kintone does by modifying the event object and returning it from your handler.Overwriting field values
Modify a field’svalue property inside the event object and return the object. Kintone applies your changes to the form:
Disabling field editing
Set a field’sdisabled property to true to make it read-only, or false to make it editable:
Showing field errors
Set a field’serror property to display a validation message below that field. Set it to null to clear the message:
Showing a record-level error
Setevent.error to display an error message at the top of the screen and cancel the current operation (e.g. prevent a save):
Redirecting after save
Setevent.url on a save-success event to navigate to a different page after the record is saved:
When multiple handlers are registered for the same event type, Kintone uses the event object returned by the last handler. If the last handler does not return the event object, field value changes from earlier handlers are not applied.
Synchronous vs. asynchronous handlers
Synchronous handlers
A synchronous handler runs, optionally modifies the event object, and returns it. This is the simplest pattern:Asynchronous handlers (Promise)
For events that support Promises, you can return aPromise from your handler. Kintone waits for the Promise to resolve before proceeding. This lets you make API calls or run other async operations before the page renders or a record is saved:
Not all events support Promises. Check the individual event reference page to confirm. If an error occurs and a Thenable is rejected, subsequent handlers for the same event type will not run.
Best practices
Always use an IIFE
Wrap your customization in an immediately-invoked function expression. This keeps your variables out of the global scope and ensures handlers are registered at script-load time:- Recommended
- With jQuery
Do not register inside DOMContentLoaded or load
Kintone initializes pages before the browser firesDOMContentLoaded and load. If you register handlers inside those callbacks, Kintone may already have fired the onload event and your handler will never run.
Script load order
When both app JavaScript files and plug-in JavaScript files are applied to an app, Kintone loads them in this order:- App JavaScript files
- Plug-in JavaScript files
kintone.events.off() to remove the existing handler first, then register the new one.
Next steps
Record list events
Onload, inline edit, field change, save, and delete events for the record list page.
Record create events
Onload, field change, save, and save-success events for the record create form.
Record edit events
Onload, field change, save, and save-success events for the record edit form.
Record detail events
Onload, delete, and process management events for the record detail page.