Fórumok

<aui:validator> for dates?

thumbnail
Richard Oliver Legendi, módosítva 10 év-val korábban

<aui:validator> for dates?

Junior Member Bejegyzések: 35 Csatlakozás dátuma: 2009.11.30. Legújabb bejegyzések
I'm trying to make a simple custom aui:validator for the birthday field on the registration form but it is simply not working. Any ideas?

<aui:input name="birthday" value="<%=birthday%>">
	<aui:validator name="custom" errormessage="some-error">
		function (val, fieldNode, ruleValue) {
			return false;
		}
	</aui:validator>
</aui:input>


What I'd like to achieve is to check if the user is 18 years old at the registration.

Any hints would be greatly appreciated!
thumbnail
Antoine Comble, módosítva 10 év-val korábban

RE: <aui:validator> for dates?

Regular Member Bejegyzések: 232 Csatlakozás dátuma: 2012.09.07. Legújabb bejegyzések
Hi,

I've a post could interest you : http://stackoverflow.com/questions/16836724/liferay-auivalidator-for-dates

Hope this help you,

Antoine
thumbnail
Richard Oliver Legendi, módosítva 10 év-val korábban

RE: <aui:validator> for dates?

Junior Member Bejegyzések: 35 Csatlakozás dátuma: 2009.11.30. Legújabb bejegyzések
Hi Antoine,

Yeah, I was the same person asking the same thing ther too :-))

Best,
Richard
thumbnail
Antoine Comble, módosítva 10 év-val korábban

RE: <aui:validator> for dates?

Regular Member Bejegyzések: 232 Csatlakozás dátuma: 2012.09.07. Legújabb bejegyzések
Hi Richard,

Sorry...


<aui:input name="birthday" value="<%=birthday%>">
    <aui:validator name="custom" errormessage="some-error">
        function (val, fieldNode, ruleValue) {
            var date = new Date(val);
            if (isDate(date) &amp;&amp; (date != INVALID_DATE) &amp;&amp; !isNaN(date)) {
                   // it's a valid date
                  var today = new Date();
                  var yyyy = today.getFullYear();
                  return (date.getFullYear() + 18) &lt; yyyy; 
            }
        }
    </aui:validator>
</aui:input>


Regards,

Antoine
thumbnail
Richard Oliver Legendi, módosítva 10 év-val korábban

RE: <aui:validator> for dates?

Junior Member Bejegyzések: 35 Csatlakozás dátuma: 2009.11.30. Legújabb bejegyzések
Hi Antoine,

Hehe, sorry, I wasn't clear enough (and there are a few things I figured out so far :-) I did not had any issues with implementing the JavaScript part . My issue was that I thought there is a trivial error with my usage, but it turned out when I try to use this on the create_account.jsp page (I had to hook it for a Liferay issue which has been fixed in the master branch but wasn't available yet in 6.1.1), it is simply not working (haven't tracked it down yet why, though).

My solution was simply verifying the date from Java and throwing an exception handled something like <liferay-ui:error exception="<%=NotOldEnoughException.class%>" message="Not old enough" /> on the JSP side. I wasn't able to use the JavaScript validator.

Anyway, thanks for your time :-)