Foros de discusión

<aui:validator> for dates?

thumbnail
Richard Oliver Legendi, modificado hace 10 años.

<aui:validator> for dates?

Junior Member Mensajes: 35 Fecha de incorporación: 30/11/09 Mensajes recientes
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, modificado hace 10 años.

RE: <aui:validator> for dates?

Regular Member Mensajes: 232 Fecha de incorporación: 7/09/12 Mensajes recientes
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, modificado hace 10 años.

RE: <aui:validator> for dates?

Junior Member Mensajes: 35 Fecha de incorporación: 30/11/09 Mensajes recientes
Hi Antoine,

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

Best,
Richard
thumbnail
Antoine Comble, modificado hace 10 años.

RE: <aui:validator> for dates?

Regular Member Mensajes: 232 Fecha de incorporación: 7/09/12 Mensajes recientes
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, modificado hace 10 años.

RE: <aui:validator> for dates?

Junior Member Mensajes: 35 Fecha de incorporación: 30/11/09 Mensajes recientes
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 :-)