jQuery Validation - form.valid() always returning true

前端 未结 3 1926
再見小時候
再見小時候 2021-01-05 00:02

I have a situation when I try to check if a form is valid, but form.valid() always returns true. But if I try to validate the individual control, it returns false.

T

3条回答
  •  北海茫月
    2021-01-05 00:34

    The question already has an accepted answer, but I believe that I've found more specific answer. I have found that if the FIRST validated element in the form has a 'name' tag then everything works as you would expect (that is, .valid() will return false if the form is invalid). The accepted answer conveniently included a 'name' tag and thus it worked.

    In normal forms, you definitely need name tags because that's what's used when the data gets submitted to the server. But in more modern environments, such as those using Knockout, there's no reason to have a 'name' tag, because the data-binding works to keep your data model updated.

提交回复
热议问题