Skip to content

Instantly share code, notes, and snippets.

@jquense
Created January 15, 2014 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jquense/8442540 to your computer and use it in GitHub Desktop.
Save jquense/8442540 to your computer and use it in GitHub Desktop.
the horror of trying to validate models rather than inputs
function validate(models, form) {
var validator = form.kendoValidator().getKendoValidator();
_.extend(validator.options.rules, getValidationShims(validator, models, form, validationError))
return validator.validate()
}
function validationError(text, models){
return text + '\n' + _.pluck(models, 'ServiceType').join('\n')
}
function getValidationShims(validator, models, form, msgFn) {
// LOOK AT THIS KENDO
function msg(key) {
return function (errors) {
validator.options.messages[key] = function (input) {
msgFn( input.attr( "data-val-" + key ), errors)
}
};
}
return _.mapValues(remoteShim, function (val, key) {
return _.partialRight(remoteShim[key], models, msg( key ) )
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment