Sheet Mode / krewSheet JavaScript API / Work with Event Handlers
In This Topic
    Work with Event Handlers
    In This Topic

    You can execute handlers for various events that occur in krewSheet.

    • Event API of krewSheet can only be used in PC version. 
    • The krewSheet event API is only available in Sheet mode, not in Xross mode.
     Registering Event Handlers

    Function

    krewsheet.events.on(event, handler(event))

    Property

    Parameter name Value to specify Required or not Description
    event String or String array Required Specify the target event type or an array of event type that binds the event handler. 
    handler(event) Function(Object) Required Handler that executes when the event is fired. Event object is common and it holds event type in the type property.
    In addition, it had the sender property that is always "krewSheet". Because the type property is same as kintone's event, it can be used for the distinction with the event of the kintone.
    For following event handlers, if you return kintone.Promise *object, it will wait for the asynchronous processing and then start event processing.
    • Event - After record view screen is displayed (app.record.index.show)
    • Event - before executing save operation (app.record.index.edit.submit)
    • Event - after saving successfully (app.record.index.edit.submit.success)
    • Event - Editing operation begins (app.record.index.edit.show)
    • Event - changing field value (app.record.index.edit.change.<Field Code)
    • Event - before deleting a record (app.record.index.delete.submit)
    *kintone.Promise object is an object that holds the method.
    ▼Reference (external website link)
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

    Return Value

    Not available.

    Sample Program
    Copy Code
    // Execute the registration of event handler
    var handler = function(event) {
        console.log(event);
    };
    kintone.events.on('app.record.index.show', function(event) {
        krewsheet.events.on('app.record.index.show', handler);
    });
    

     

    • In kewSheet, the event handlers are registered after the krewSheet is loaded. Therefore, please register after kintone's record view screen is displayed.
     Deleting a specific event handler within a specific event type

    Function

    krewsheet.events.off(event, handler(event))

    Property

    Parameter name Value to specify Required or not Description
    event String or String array Required Specify the event type or an array of event types that registered the event handler to be deleted.
    handler(event) Function(Object) Required Event handler to be deleted. Specify the same object as the one specified while registering an event.

    Return value

    • true:If at least one event handler is deleted successfully.
    • false:If no event handlers to be deleted are found.
    Sample Program
    Copy Code
    // Execute the deletion of event handler.
    var handler = function(event) {
        console.log(event);
    };
    krewsheet.events.off('app.record.index.show', handler);
    
     Deleting all event handlers within a specific event type

    Function

    krewsheet.events.off(event)

    Property

    Parameter name Value to specify Required or not Description
    event String or String array Required Specify the event type or an array of event types that registered the event handler to be deleted.

    Return value

    • true:If at least one event handler is deleted successfully.
    • false:If no event handlers to be deleted are found.
    Sample Program
    Copy Code
    krewsheet.events.off('app.record.index.show');
    
     Deleting all event handlers

    Function

    krewsheet.events.off()

    Return value

    • true:If at least one event handler is deleted successfully.
    • false:If no event handlers to be deleted are found.
    See Also