[4.0.4] document.ready and Navigation Issue - Forum - Rollbase - Progress Community

[4.0.4] document.ready and Navigation Issue

 Forum

[4.0.4] document.ready and Navigation Issue

This question has suggested answer(s)

Hello, 

Just came across another different behavior with regards to document.ready and navigation through record.

Basically, before 4.0.4 we were doing document.ready on many view pages and this code was running all the time, both on load of the page and when navigating (next or previous) to another record.

Now it does not work like that anymore, because the navigation logic has changed I guess.

So basically this is causing us issues as the code we are having on document.ready is not always running when we load a page after navigating to it.

Can you please provide us with a way to make sure our code will run all the time on load and after navigation ?

Thanks

Meryem

All Replies
  • Yes Meryem, code written to run on document.ready in custom script components will be affected if navigation is accomplished via Page Ajax Update.

    We have ensured that any onload handlers attached as Page properties are not affected.

    In custom script components, request you run any page customization scripts on Rollbase custom event i.e. rb.newui.util.customEvents.rbs_pageRender. This event will be fired for both Page Refresh & Page Ajax update cases.

    Eg:

    rb.newui.util.addEventListener(rb.newui.util.customEvents.rbs_pageRender, function () {

       //Once page is rendered, we can start querying for page elements.. in this case input control for field 'timeA'.

       var fieldContext = rbf_getFieldContext('timeA');

       if(fieldContext){

        fieldContext.getKendoConfig().setOptions({interval: 10});

       }

     });

    Regards,
    Siraj.
  • Hi Siraj,

    if I do this for example :

    rb.newui.util.addEventListener(rb.newui.util.customEvents.rbs_pageRender, function () {

     alert('Page rendered');

    });

    is the alert supposed to popup when the page is rendered ?

    I just tried this bit of code in one of my scripts and there is no alert coming.

    Also, i won't be using fieldContext as I am doing manipulation of some buttons not fields..

    Thanks

    Meryem

  • Yes, this should work. On both page refresh & navigation to this page via Ajax.

    Can you please look into the console & see if any issues are reported?

    Regards,
    Siraj.
  • It is alerting once in two times, i.e if I keep refreshing the page, one time I got the alert and the next time nothing.

    Same behavior if I keep clicking on next/previous.

    Meryem

  • Siraj, Can you let me know if you are able to reproduce this behavior please?

  • Meryem, have given it a try & can confirm that it works as expected i.e. fires for each page refresh.

    So you are seeing ambigous behavior related to firing of this event. Can you please re-confirm that you are not seeing any console errors.

    Regards,
    Siraj.
  • That's strange. Would this be affected by any document.ready code ?

    We have some custom code in document.ready on those pages, thats the only thing I can see

  • Siraj,

    We have some docuemnt.ready code in a custom javascript file, that we are importing from main.js.

    I think this has something to do with the behavior I am seeing.

    Also, if I comment out all our code, and call customEvent.rbs_pageRender from that js file it will run only on refreshing not on navigation. When I call it form the page itself then it is working as you are describing.

    We basically need this code, and I will have to leave it in that file, is that a problem for the custom event to run ?

    Thanks,

    Meryem

  • Meryem, can you please log a support case for this. Better if have screen sharing to dicuss this issue further.

    Regards,
    Siraj.
  • Hi Siraj,

    Yes sure I will thank you.

    Meryem

  • Hello Siraj,

    We tried your suggestion but we are still facing the same issue. Page render does not work after rb-ui.js.

    What do you think it might be then ?

    Thank you

    Meryem

  • Right, we are just partly solving the problem. Now the rb-ui.js JS definitions are available to your scripts. However, rbf_getPageContext().getCanvasEl() will return NULL when used in header script.

    Request you to refactor your code such as, abc.js (name changed) which is downloaded as header script should just include onload function definition. i.e.

    function onLoad(){

    //tab movement related code

    });

    However, the call to this util function should come from a script component configured on the page & as follows:

    <script>

    rb.newui.util.addEventListener(rb.newui.util.customEvents.rbs_pageRender, onLoad);

    </script>

    Hope this helps.

    Regards,
    Siraj.
  • Hi Siraj,

    This script abc.js we are loading as header script contains functions we want to call on ALL pages across all the applications.

    It is not very convenient to call the onLoad functions on each and every page. Also, in terms of usability by customers, this is not going to work as we can not ask them to add those onLoad functions to each page.

    Is there another way we could avoid this please? We need to be able to call a function from one place and run it on load of all pages.

    Thanks,

    Meryem

  • Ok. In your header script, bind the function that is to be executed onLoad, as given below:

    $(document).on(rb.newui.util.customEvents.rbs_pageRender,onLoad});

    Also, please file an Enhancement Request asking for configuration option to inject custom scripting behavior as a tenant-wide feature instead of application-wide.

    Regards,
    Siraj.
  • Minor correction:

    $(document).on(rb.newui.util.customEvents.rbs_pageRender,onLoad);

    Regards,
    Siraj.