I am using Liferay portal 7.4 GA 105, I am upgrading it from 7.2. So, I have faced issue that when to open a document and media dialogue box on a button click it shows an error on console that A.LiferayItemSelectorDialog is not a constructor
. Although it works fine when using in Liferay 7.2.
Here is the JSP file having code/script to open a dialogue box.
<%@ taglib prefix="aui" uri="http://liferay.com/tld/aui" %>
<%
String itemSelectorURL = GetterUtil.getString(request.getAttribute("itemSelectorURL"));
%>
<aui:script use="liferay-item-selector-dialog">
console.log("test");
var parsedHtmlGeneratorId = '';
jQuery_html('.chooseImage').on(
'click',
function(event) {
parsedHtmlGeneratorId = event.currentTarget.dataset.parsedid;
var itemSelectorDialog = new A.LiferayItemSelectorDialog(
{
eventName: 'ItemSelectedEventName',
on: {
selectedItemChange: function(event) {
var selectedItem = event.newVal;
if (selectedItem) {
itemSrc = selectedItem.value
var parsedItemId = '<portlet:namespace />' + parsedHtmlGeneratorId;
document.getElementById(parsedItemId).value = itemSrc;
}
}
},
title: 'Select Image',
url: '<%= itemSelectorURL.toString() %>'
}
);
itemSelectorDialog.open();
}
);
</aui:script>
Here is my button which I used to call that script
<aui:button data="<%=dataMap%>" name="chooseImage"
value="Browse" cssClass="chooseImage btn-primary mt-1" />
I have added all the necessary code in the portlet.java
file, including references to itemSelector
and all the required code available in the Liferay documentation for its usage.
If anyone faces this problem, please recommend a solution and an approach to follow to resolve this issue in Liferay 7.4.
Thanks in Advance.
AUI is on the way out, so there's a good probability that you'll have to migrate your code to a newer UI layer.
Luckily there's Liferay documentation about how to implement an item selector based on newer versions. It looks like it's now based on Liferay.Util.openSelectionModal
, so your implementation will need to adapt to the new way.