Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: anutron/mootools-more
...
head fork: anutron/mootools-more
  • 1 commit
  • 6 files changed
  • 0 commit comments
  • 1 contributor
Commits on Jun 25, 2011
@anutron Fixes Lighthouse #568 d5c218a
View
12 Docs/Forms/Form.Validator.md
@@ -405,6 +405,18 @@ Displays an error if the field is empty.
Error Msg: "This field is required"
+Validator: length {#Validators:length}
+--------------------------------------------
+
+Displays a message if the input value is not precisely the supplied length.
+
+Error Msg: "Please enter [required length] characters (you entered [input length] characters)"
+
+### Note
+
+You must add this name AND properties for it to your input.
+
+
Validator: minLength {#Validators:minLength}
--------------------------------------------
View
12 Source/Forms/Form.Validator.js
@@ -484,6 +484,18 @@ Form.Validator.addAllThese([
return el.get('value');
});
}
+ }],
+
+ ['length', {
+ errorMsg: function(element, props){
+ if (typeOf(props.length) != 'null')
+ return Form.Validator.getMsg('length').substitute({reqLength: props.length, length: element.get('value').length });
+ else return '';
+ },
+ test: function(element, props){
+ if (typeOf(props.length) != 'null') return (element.get('value').length == props.length || element.get('value').length == 0);
+ else return true;
+ }
}]
]);
View
1  Source/Locale/Locale.en-US.Form.Validator.js
@@ -21,6 +21,7 @@ provides: [Locale.en-US.Form.Validator]
Locale.define('en-US', 'FormValidator', {
required: 'This field is required.',
+ length: 'Please enter {reqLength} characters (you entered {length} characters)',
minLength: 'Please enter at least {minLength} characters (you entered {length} characters).',
maxLength: 'Please enter no more than {maxLength} characters (you entered {length} characters).',
integer: 'Please enter an integer in this field. Numbers with decimals (e.g. 1.25) are not permitted.',
View
2  Tests/Interactive/Forms/Form.Validator.Inline.html
@@ -14,6 +14,8 @@
<dl>
<dt>this cannot be empty</dt>
<dd><input name="a" class="required"></dd>
+ <dt>must be 5 characters long</dt>
+ <dd><input name="a" class="length:5"></dd>
<dt>this must be an integer (-1,0,1,2,3, etc)</dt>
<dd><input name="b" class="required validate-integer"></dd>
<dt>this must be numeric (0, 1.3, -5.2, 10, etc) </dt>
View
2  Tests/Interactive/Forms/Form.Validator.Inline_(data-).html
@@ -14,6 +14,8 @@
<dl>
<dt>this cannot be empty</dt>
<dd><input name="a" data-validators="required"></dd>
+ <dt>must be 5 characters long</dt>
+ <dd><input name="a" data-validators="length:5"></dd>
<dt>this must be an integer (-1,0,1,2,3, etc)</dt>
<dd><input name="b" data-validators="validate-integer"></dd>
<dt>this must be numeric (0, 1.3, -5.2, 10, etc) </dt>
View
22 Tests/Specs/1.3/Forms/Form.Validator.js
@@ -127,6 +127,28 @@ describe('Form.Validator', function(){
});
+ describe('length', function(){
+
+ var validator = getValidator('length');
+
+ function length(value){
+ return { length: value };
+ }
+
+ it('should return false for fields with a length less than the specified length', function(){
+ expect(validator.test(createInput('12345'), length(10))).toEqual(false);
+ });
+
+ it('should return false for fields with a length greater than the specified length', function(){
+ expect(validator.test(createInput('12345'), length(3))).toEqual(false);
+ });
+
+ it('should return true for fields with a length equal to the specified length', function(){
+ expect(validator.test(createInput('12345'), length(5))).toEqual(true);
+ });
+
+ });
+
describe('minLength', function(){
var validator = getValidator('minLength');

No commit comments for this range

Something went wrong with that request. Please try again.