开发者

What changes to DOM are made when MVC Validation triggers?

I have a form in a modal window that is currently performing some validation. (I am using ASP.NET MVC, JQuery UI, ajax forms, data annotations and unobtrusive is active)

When this validation triggers I have noticed so far that it does a few things:

1: my validation summary gets it's class changed from .validation-summary-valid to .validation-summary-errors

2: my invalid inputs have a class added to then called .input-validation-error

3: my validation messages get their class changed from .field-validation-valid to .field-validation-error

But there is something else that it is doing and I cant work out how it is tracking this.

I have a textbox that is required, before triggering the validation i can select inside this box, then select another box and the validation will be silent.

But as soon as i trigger the validation by clicking submit with an empty textbox, i can select the textbox and type something to remove the validation instantly, but if 开发者_JAVA百科i then null it and select a different box this error is re-applied without re-submitting.

So my question is: what has changed, how does it know that I have attempted to submit already?


When validate is called, it adds a class to each input/select that is supposed to be validated. When the input/select is not valid it adds a class to the input/select:

class="input-validation-error"

When it is valid, it adds:

class="valid"

Validation only fires on the control when you change the value, not when it loses focus.

Validation fires on change, even before you submit the form. Take a required textbox, add a value to it, and tab off ... then go back and remove that value, and you should see the textbox highlighted red.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜