Tuesday, 28 November 2017

Alloy UI Validator

1--><aui:validator name="required" />
Usage:Field should not be empty.

2--><aui:validator name="digits" />
Usage:Only digits allowed in this field.

3--><aui:validator name=”range”>
[1,20]
</aui:validator>
Usage:Only digits between 1 and 20 allowed.

4--><aui:validator name="equalTo">
'#<portlet:namespace />password1'
</aui:validator>
Usage:It compares two field passwords.

5--><aui:validator name="alpha" />
Usage:Only alphabets allowed in this field.

6--><aui:validator name="date" />
Usage:Only date allowed in this field.

7--><aui:validator name="alphanum" />
Usage:Only alphanumeric characters allowed in this field.

8--><aui:validator name="email" />
Usage:Only email address allowed in this field.

9--><aui:validator name="max">
'5'
</aui:validator>
Usage:Only value digits less than or equal to 5.

10--><aui:validator name="min">
'5'
</aui:validator>
Usage:Only allow value greater than or equal to 5.

11--><aui:validator name="maxLength">
'10'
</aui:validator>
Usage:Only allow maximum length of 10 characters.

12--><aui:validator name="minLength">
'10'
</aui:validator>
Usage:Only allow minimum length of 10 characters.

13.<aui:validator name="rangeLength" >
[2,10]
</aui:validator>
Usage:No of characters should be between 2 and 10.

14.<aui:validator name="url" />
Usage:Only URL is allowed in this field.

15.<aui:validator name="acceptFiles">
'jpeg, png'
</aui:validator>
Usage:Only allow files of the specified type.If all of these validation rules don't meet your needs, you can write custom rules, too.
This can be accomplished by using the "custom" rule name, custom "errorMessage"
attribute (more on this attribute further down), and a short Alloy Javascript function.
Your custom rule can do anything inside the curly braces as long as the return result
is a boolean. "val" is the value of the field (what the user typed in), "fieldNode" is
the node the validator is attached to, and ruleValue is what's inside the tag (in this
case, it's irrelevant because it is the script itself).


16--><aui:validator name="custom"
errorMessage="value-cannot-be-test">
function(val, fieldNode, ruleValue) { return (val !=
'test') }
</aui:validator>



NOTE:DEFAULT ERROR MESSAGE WE GET CAN BE SEEN IN

SERVER/TOMCAT/WEBAPPS/ROOT/HTML/JS/LIFERAY/FORM.JS

DEFAULT ERROR MESSGAES:

acceptFiles:
Liferay.Language.get(‘please-enter-a-file-with-a-valid-extens
ion-x’),

alpha:
Liferay.Language.get(‘please-enter-only-alpha-characters’),

alphanum:
Liferay.Language.get(‘please-enter-only-alphanumeric-characte
rs’),

date: Liferay.Language.get(‘please-enter-a-valid-date’),

digits: Liferay.Language.get(‘please-enter-only-digits’),

email:
Liferay.Language.get(‘please-enter-a-valid-email-address’),

equalTo:
Liferay.Language.get(‘please-enter-the-same-value-again’),

max:
Liferay.Language.get(‘please-enter-a-value-less-than-or-equal
-to-x’),

maxLength:
Liferay.Language.get(‘please-enter-no-more-than-x-characters’
),

min:
Liferay.Language.get(‘please-enter-a-value-greater-than-or-equal-to-x’),

minLength:
Liferay.Language.get(‘please-enter-at-list-x-characters’),

number: Liferay.Language.get(‘please-enter-a-valid-number’),

range:
Liferay.Language.get(‘please-enter-a-value-between-x-and-x’),

rangeLength:
Liferay.Language.get(‘please-enter-a-value-between-x-and-x-ch
aracters-long’),

required: Liferay.Language.get(‘this-field-is-required’),

url: Liferay.Language.get(‘please-enter-a-valid-url’)
We can also custom error message by writing errorMessage in validator.

For Ex:
<aui:validator name="url"
errorMessage="this-field-must-be-a-valid-url" />

TEST

I am Java Developer. I have 6 year Experiance in this field and like to post in blogging. So keep sharing and like my post

1 comments:

 

Copyright @ 2017 Liferay Article.