Permalink
Browse files

Merge pull request #1270 from SergioCrisostomo/fix-1030

Type error fix for empty string on 'validate-date'
  • Loading branch information...
arian committed Jun 23, 2014
2 parents 5f82f73 + df950d0 commit 94bf5a95704434a828fe6fbac6abdeb169f85fce
Showing with 12 additions and 6 deletions.
  1. +8 −6 Source/Forms/Form.Validator.js
  2. +4 −0 Specs/Forms/Form.Validator.js
@@ -455,13 +455,15 @@ Form.Validator.addAllThese([
value = element.get('value'),
wordsInValue = value.match(/[a-z]+/gi);
if (wordsInValue && !wordsInValue.every(dateNouns.exec, dateNouns)) return false;
if (wordsInValue && !wordsInValue.every(dateNouns.exec, dateNouns)) return false;
var date = Date.parse(value),
format = props.dateFormat || '%x',
formatted = date.format(format);
if (formatted != 'invalid date') element.set('value', formatted);
return date.isValid();
var date = Date.parse(value);
if (!date) return false;
var format = props.dateFormat || '%x',
formatted = date.format(format);
if (formatted != 'invalid date') element.set('value', formatted);
return date.isValid();
}
}],
@@ -314,6 +314,10 @@ describe('Form.Validator', function(){
expect(validator.test(createInput('Boo 12'))).toEqual(false);
});
it('should return false, instead of Type Error, when passed a empty string', function(){
expect(validator.test(createInput(' '))).toBeFalsy()
});
it('should return true for fields whose value parses to a date', function(){
expect(validator.test(createInput('Nov 12'))).toEqual(true);
expect(validator.test(createInput('10-10-2000'))).toEqual(true);

0 comments on commit 94bf5a9

Please sign in to comment.