haacked / aspnet-client-validation

A client validation library for ASP.NET MVC that does not require jQuery

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using watch, validation message spans aren't added to the register if new fields are added to form

geoffbeaumont opened this issue · comments

The problem is that the root passed to ValidationService.prototype.scanMessages = function (root, remove) is the new element detected, not the form. scanMessages checks for a form and registers the message under the form, but it only walks down the DOM, so if the new element is within the form no form is found and the message is not registered.

In my case I can work round this by adding form attributes to the message spans before adding them to the DOM, but that probably isn't always going to be possible.

Probably need to walk up the DOM until finding a form if the root isn't a form and doesn't contain any forms. Only if that doesn't find a form (in which case the new element detected wasn't relevant) should the function return without searching for message spans to register.

If I'm understanding correctly, this is what #65 is meant to solve. You might try that branch and see if it resolves your issue?

@dahlbyk Yes, that's the exact scenario I have - I'll test the code from #65, but it looks to me like it'll fix it without any side effects beyond a tiny performance impact.

@dahlbyk I can confirm that #65 fixes this for me. I'm not seeing any side effects.

Just need @haacked to :shipit: