суббота, 5 февраля 2011 г.

small validation helper for MVC3 unobtrusive validation

// The problem: MVC 3 unobtrusive validation attach validation handlers only 
// when global validation script loaded. It use parse() method to find items to
// attach validation to. If some page content is loading after parse called, 
// then it is not parsed, as a result no validation work with it.
// Possible solution: call $.validator.unobtrusive.parse(selector) each time when add new content
// that claims validation.
// It's just a helper to call it automatically like this example:
//  $('#panel').html(newContent).initValidation();
// instead of 
//  $('#panel').html(newContent);
//  $.validator.unobtrusive.parse('#panel');
$.fn.initValidation = function () {
 return this.each(function (i,e) {
  $.validator.unobtrusive.parse(e);
 });
};

0 коммент.:

Отправить комментарий