Created
September 22, 2011 11:01
-
-
Save saimonmoore/1234544 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Run validations | |
*/ | |
TaskList.validate = function (attrs) { | |
//check for required attributes | |
var errors = {} | |
, i18n = Teambox.helpers.jade.i18n; | |
_(['name']).each(function(attr) { | |
if (!attrs[attr].length) { | |
errors[attr] = errors[attr] || []; | |
errors[attr].push(i18n('task_lists.errors.' + attr + '.cant_be_blank')); | |
} | |
}) | |
if (attrs.name.length && attrs.name.length > 255) { | |
errors.name = errors.name || []; | |
errors.name.push(i18n('task_lists.errors.name.too_long')); | |
} | |
//check start/end date | |
var startDate = attrs['start_on'] | |
, endDate = attrs['finish_on'] | |
, hasStartDate = startDate && startDate.length | |
, hasEndDate = endDate && endDate.length; | |
if (hasStartDate && hasEndDate) { | |
if (Date.parse(startDate) > Date.parse(endDate)) { | |
errors.finish_on = errors.finish_on || []; | |
errors.finish_on.push(i18n('task_lists.errors.finish_on.end_date_less_than_start_date')); | |
} | |
} | |
return Object.keys(errors).length ? errors : false; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment