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
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});
}
});
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?
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.
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.
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.
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.
Minor correction:
$(document).on(rb.newui.util.customEvents.rbs_pageRender,onLoad);
Added the idea:
+1 please :)
Cheers.
Iram
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?
Cheers.
Iram
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.
Cheers.
Iram
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.