Callback for state change


I am customizing the UI of ERPNext, want to know if there is some callback that fires whenever the state is changed.

Thanks in advance.

Zain Sajjad.

Which state?

Whenever I click on any link state is changed. Example: When app-icon is clicked and module is opened and view is loaded.

Actually I wanted to change the HTML of input fields once they are loaded in DOM, I wanted a function to execute whenever the new view has been loaded. Solution that i found is to register an event of DOM mutation and put my functionality there.

var observeDOM = (function(){
    var MutationObserver = window.MutationObserver || window.WebKitMutationObserver,
        eventListenerSupported = window.addEventListener;

    return function(obj, callback){
        if( MutationObserver ){
            // define a new observer
            var obs = new MutationObserver(function(mutations, observer){
                if( mutations[0].addedNodes.length || mutations[0].removedNodes.length )
            // have the observer observe foo for changes in children
            obs.observe( obj, { childList:true, subtree:true });
        else if( eventListenerSupported ){
            obj.addEventListener('DOMNodeInserted', callback, false);
            obj.addEventListener('DOMNodeRemoved', callback, false);

// Observe a specific DOM element:
observeDOM( document.body ,function(){ 
    //My customizations

Thanks for your help. :smile:

1 Like