Search code examples
jqueryasp.net-mvcjquery-validateunobtrusive-validation

Validate prefilled jQuery form (invalidate on first field clear, ASP.NET and unobtrustive)


I have a form that can be filled, saved, loaded and re-edited.

When it is loaded and re-edited, it probably begins its life valid. When a field is valid upon load, I want it to invalidate immediately when it is edited contrary to rules. That's my question in a nutshell, and I suspect this is supported by some configuration option I can't find.


Currently, it works properly (the way desired above) only after: 1) it is edited, 2) then the field loses focus while valid, 3) then is edited it again. So it takes an extra valid loss of focus to visualize errors for a pre-filled form.

If it is empty on load (such as the first visit) it should not show errors.

I'm using the following already in my framework:

  • jQuery.validate (the 'approved' one, and the focus of my question)
  • jQuery unobtrusive validation adapter for ASP.NET MVC 3

I don't currently run any custom code to activate this, since the 'unobtrusive' adapter initializes validation (but I'd be happy to, to fix this). I've tried adding 'form.valid()' on page load, but it doesn't fix the above and in fact breaks more stuff.

Thanks, Shannon


Solution

  • I've dug into the validation plug-in, and opened a ticket for what I believe is a defect.

    https://github.com/jzaefferer/jquery-validation/issues/146

    Shannon