Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Liferay <liferay-ui:input-date> control

Hy all,

I'm new to Liferay and I making some porting from jsp to Liferay portal.

If I have a portlet jsp with two date in it like: FromDate ToDate and use two different liferay-ui:input-date one for each date field like:

    ...
<%-- From DATE --%>
<tr>
    <td>
        From date :
    </td>
    <td>
        <liferay-ui:input-date
            dayParam='<%= "strDataRegDa" + "Day" %>'
            dayValue="<%=Integer.parseInt(strDataRegDa.substring(0,2))%>"
            dayNullable="<%= false %>"
            monthParam='<%= "strDataRegDa" + "Month" %>'
            monthValue="<%=(Integer.parseInt(strDataRegDa.substring(3,5))) -1 %>"
            monthNullable="<%= false %>"
            yearParam='<%= "strDataRegDa" + "Year" %>'
            yearValue="<%=Integer.parseInt(strDataRegDa.substring(6))%>"
            yearNullable="<%= false %>"
            yearRangeStart="<%= 1980 %>"
            yearRangeEnd="<%= 2050 %>"
            firstDayOfWeek="<%= Calendar.MONDAY - 1 %>"
            imageInputId='<%= "ceremonyDate"%>'
            disabled="false" >
        </liferay-ui:input-date>
    </td>
</tr>

<%-- To DATE --%>
<tr>
    <td>
        To date :
    </td>
    <td>
        <liferay-ui:input-date
            dayParam='<%= "strDataRegA" + "Day" %>'
            dayValue="<%=Integer.parseInt(strDataRegA.substring(0,2))%>"
            dayNullable="<%= false %>"
            monthParam='<%= "strDataRegDa" + "Month" %>'
            monthValue="<%=(Integer.parseInt(strDataRegA.substring(3,5))) -1 %>"
            monthNullable="<%= false %>"
            yearParam='<%= "strDataRegDa" + "Year" %>'
            yearValue="<%=Integer.parseInt(strDataRegA.substring(6))%>"
            yearNullable="<%= false %>"
            yearRangeStart="<%= 1980 %>"
            yearRangeEnd="<%= 2050 %>"
            firstDayOfWeek="<%= Calendar.MONDAY - 1 %>"
            imageInputId='<%= "ceremonyDate"%>'
            disabled="false" >
        </liferay-ui:input-date>
    </td>
</tr>
....

is there a way to control that ToDare is >= FromDate ?

With pure jsp I can do that via javascript.

But with Liferay how can achieve that ?

like image 457
dbrembilla Avatar asked Nov 30 '11 08:11

dbrembilla


2 Answers

In our project I used manual Validation for the two dates in my Portlet Class for the dates. I had also searched but couldn't get anything which liferay provides. Through javascript don't know if Alloy UI provides something.

So in my humble opinion liferay does not provide any functionality for validating the two dates (atleast as of now), as can be seen from some out-of-box liferay portlets which does not have this validation like for example the Announcements-portlet with display-date and expiry-date.

like image 66
Prakash K Avatar answered Oct 30 '22 17:10

Prakash K


Maybe you need something like custom validator. Try this in your jsp:

<liferay-ui:input-date name="fromDate"></liferay-ui:input-date>
<liferay-ui:input-date name="toDate">
    <aui:validator name="custom" errorMessage="your custom validation msg">
    function(val, fieldNode, ruleValue) 
    {
        // No error when toDate is blank
        if(val == ""){
            return true;
        }
        var fromDate;
        var toDate;
        var result=false;

        var fromDateObj = document.getElementById("<portlet:namespace />fromDate");
        if(fromDateObj) {
            fromDate = new Date(fromDateObj.value);
        }else{
            result = false;
        }

        toDate = new Date(val);

        if(fromDate && toDate){
            result = (toDate.getTime() > fromDate.getTime());
        }else{
            result = false;
        }

        return result;
    } 
    </aui:validator>
</liferay-ui:input-date>

Hope this helps you.

Thanks.

like image 30
AGi Avatar answered Oct 30 '22 17:10

AGi