Foren

<aui:validator> for dates?

thumbnail
Richard Oliver Legendi, geändert vor 10 Jahren.

<aui:validator> for dates?

Junior Member Beiträge: 35 Beitrittsdatum: 30.11.09 Neueste Beiträge
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, geändert vor 10 Jahren.

RE: <aui:validator> for dates?

Regular Member Beiträge: 232 Beitrittsdatum: 07.09.12 Neueste Beiträge
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, geändert vor 10 Jahren.

RE: <aui:validator> for dates?

Junior Member Beiträge: 35 Beitrittsdatum: 30.11.09 Neueste Beiträge
Hi Antoine,

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

Best,
Richard
thumbnail
Antoine Comble, geändert vor 10 Jahren.

RE: <aui:validator> for dates?

Regular Member Beiträge: 232 Beitrittsdatum: 07.09.12 Neueste Beiträge
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, geändert vor 10 Jahren.

RE: <aui:validator> for dates?

Junior Member Beiträge: 35 Beitrittsdatum: 30.11.09 Neueste Beiträge
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 :-)