掲示板

<aui:validator> for dates?

thumbnail
10年前 に Richard Oliver Legendi によって更新されました。

<aui:validator> for dates?

Junior Member 投稿: 35 参加年月日: 09/11/30 最新の投稿
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
10年前 に Antoine Comble によって更新されました。

RE: <aui:validator> for dates?

Regular Member 投稿: 232 参加年月日: 12/09/07 最新の投稿
Hi,

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

Hope this help you,

Antoine
thumbnail
10年前 に Richard Oliver Legendi によって更新されました。

RE: <aui:validator> for dates?

Junior Member 投稿: 35 参加年月日: 09/11/30 最新の投稿
Hi Antoine,

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

Best,
Richard
thumbnail
10年前 に Antoine Comble によって更新されました。

RE: <aui:validator> for dates?

Regular Member 投稿: 232 参加年月日: 12/09/07 最新の投稿
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
10年前 に Richard Oliver Legendi によって更新されました。

RE: <aui:validator> for dates?

Junior Member 投稿: 35 参加年月日: 09/11/30 最新の投稿
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 :-)