Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 94bf5a9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Source/Forms/Form.Validator.js
Expand Up @@ -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();
}
}],

Expand Down
4 changes: 4 additions & 0 deletions Specs/Forms/Form.Validator.js
Expand Up @@ -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);
Expand Down

0 comments on commit 94bf5a9

Please sign in to comment.