[4.0.4] document.ready and Navigation Issue

Posted by Meryk on 05-Jan-2016 06:36


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 ?



All Replies

Posted by Mohammed Siraj on 05-Jan-2016 06:48

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.


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');


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



Posted by Meryk on 05-Jan-2016 08:23

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..



Posted by Mohammed Siraj on 05-Jan-2016 08:33

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?

Posted by Meryk on 05-Jan-2016 08:40

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.


Posted by Meryk on 05-Jan-2016 09:29

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

Posted by Mohammed Siraj on 05-Jan-2016 10:06

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.

Posted by Meryk on 05-Jan-2016 10:35

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

Posted by Meryk on 05-Jan-2016 11:15


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 ?



Posted by Mohammed Siraj on 06-Jan-2016 05:11

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

Posted by Meryk on 06-Jan-2016 05:54

Hi Siraj,

Yes sure I will thank you.


Posted by Meryk on 08-Jan-2016 10:14

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


Posted by Mohammed Siraj on 10-Jan-2016 12:30

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:


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


Hope this helps.

Posted by Meryk on 11-Jan-2016 03:29

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.



Posted by Mohammed Siraj on 11-Jan-2016 04:12

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


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

Posted by Mohammed Siraj on 11-Jan-2016 04:13

Minor correction:


Posted by IramK on 11-Jan-2016 06:16
Posted by IramK on 11-Jan-2016 09:13

Hello [mention:78c86023544844079dc6455a4a7a4d57:e9ed411860ed4f2ba0265705b8793d05],

Hope you are fine. So after a lot of trial and error, we have been looking at this issue across different apps and have the following to report back based on our finding. As a general perspective, we think that this is not as reliable as how document.ready was. Let me explain to you the three scenario's we have. Feel free to let us know what you think.

[mention:056f109241554e68b37b1d3f5057632e:e9ed411860ed4f2ba0265705b8793d05]: Feel free to add your findings as well if you think I have missed out on anything.

1) document.ready function: As we now have understood the fact that using document.ready can no longer guarantee that the page contents are loaded and everything will work as before because of AJAX loading being used. In response to that we are supposed to use pageRender function as mentioned in this post before. We are fine with that.

2) Page Render: This does seem to work on the page itself, however we have noticed an issue with this in a couple of places already whereby when you reload the page and then navigate to another record, the pageRender is not really working and the functions within that pagRender doesn't fire. Not sure why.

3) onload Event of the View page: This seems to work fine without any issues.

From the above options listed above, we have only found the third option to work reliably but the issue is we cannot use this from the server itself. Could you possibly point us out in the right direction please?



Posted by IramK on 12-Jan-2016 06:03

Hello [mention:78c86023544844079dc6455a4a7a4d57:e9ed411860ed4f2ba0265705b8793d05],

I have been noticing some issues with PageRender when I had the rb.new.util.. etc code to the page itself. It does run most of the times but doesn't run in the following situations:

1) Does not run when a tab is loaded (when we click on a tab), however document.ready still works once the tab is loaded

2) Does not necessarily run the page render when we navigate between records, even here document.ready works always

Any suggestions if this would be fixed in the next release or 4.0.6 please? Kindly let me know.



Posted by Mohammed Siraj on 13-Jan-2016 03:20

Iram, regarding:

1) Does not run when a tab is loaded (when we click on a tab), however document.ready still works once the tab is loaded

Yes, it is not meant to be fired on Tab Ajax load. As discussed in the call, will add a custom event for this purpose going forward. Regarding document.ready, jquery behavior is that it will fire this event immediately if the DOM is already loaded, else it is delayed & fired when DOM is complete & ready.

2) Does not necessarily run the page render when we navigate between records, even here document.ready works always

It is supposed to work in this case & strongly feel it does, as we found out while debugging during the call.

This thread is closed