Liferay.on("allPortletsReady") getting fired before all portlets are ready
Written By
Anushka Tiwari
How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!
While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.
Legacy Article
You are viewing an article from our legacy "FastTrack"
publication program, made available for informational purposes. Articles
in this program were published without a requirement for independent
editing or verification and are provided"as is" without
guarantee.
Before using any information from this article, independently verify its
suitability for your situation and project.
Issue
- Liferay.on("allPortletsReady") getting fired before all portlets are ready
- Steps to reproduce:
- Start the server.
- Create a form with multiple text fields, single selection radio button set with multiple options, select list fields, etc. with some rules working on these fields.
- Save/Publish the form and configure a page to show this form with the Forms portlet.
- On the page showing the form, add the following javascript code in the configuration settings (Configure page > Design > Customization > Javascript) :
function computeIndex() {
$("div.ddm-form-page-container input[type='radio']").each(function(index) {
console.log(index);
});
}
Liferay.on("allPortletsReady", function() {
console.log("All portlets ready");
computeIndex();
});
- Save settings and publish the page.
- Go to the page and open the browser's console
Expected result:
In the console log, you get "All portlets ready" and the IDs for the radio buttons.
Actual result:
Only the "All portlets ready" text is displayed.
Additional info:
Adding a delay to the part that displays the IDs cause the script to behave as expected. This leads us to believe that the Liferay.on("allPortletsReady", function() is fired before it should
Resolution
- So the definition of the “allPortletsReady” function is as follows: This function gets loaded when everything, including the portlets, is on the page.
- This can be confusing as it means all content from the original HTTP request is on the page (markup, direct resources pointed by them like CSS, images, or JS are loaded), but does not cover JS scripts in the page that need to make further fetch requests to load data, which is what form is doing. Resource loading is often confused with "dom stability/completeness".
- So the “allPortletsReady” function is behaving as it should.
- Also, make sure that the IDs are displayed in the logs other than adding a delay manually, need to create the own custom form field.
- The custom form field could be similar to the Radio form field, but it would be possible to increment the code to show the subscriber count next to the label.
Did this article resolve your issue ?