2

I am struggling with MVC4 and JQuery validation.

We have a decent number of textboxes with their validation message next to them.

Once they have entered valid messages in all of them the messages all go away. but when I do:

var valid = $('form').valid();

it will always return false. got this from (How to fire jQuery function only if form is valid)

I have no idea what is still wrong with the form. Is there a way of getting the error messages for the form?

I have tried hooking up the show errors on the validate() such as described here:

Jquery validate showerrors display name

but this never populates any information. As I test I put this on the change of every input box:

   if ($('form').valid()) {
      alert('the form is valid');
   }
   else if(!$('form').valid()) {
       alert('the form is NOT valid');                                
   }

but it will always return NOT valid.

EDIT

Was just going about to create the online sample (as requested by webdeveloper). Chrome was hiding some of my HTML (using jquery tab control). So went to IE to get the source and the validation worked. Then tried it in FF and it worked. So it seems it is only broken in Chrome.

EDIT 2

Created the jsfiddle.net page: http://jsfiddle.net/qN3Cn/1/

In IE the form will return valid, in chrome it is not valid.

Community
  • 1
  • 1
Jon
  • 15,110
  • 28
  • 92
  • 132

2 Answers2

4

It could be error of hidden field, you can view all errors in console:

$('form').validate().errorList
webdeveloper
  • 17,174
  • 3
  • 48
  • 47
  • this was helpful. When I had a "real" error with a textbox this would return an object with an array containing the error. When I fixed all the errors it would return an empty array, but still invalid: $('form').validate().errorList; [] $('form').valid() false – Jon Sep 21 '12 at 17:23
  • @Jon Please, create issue with http://jsfiddle.net/ and then we could view your problem. Include rendered html-markup and validation libs. – webdeveloper Sep 21 '12 at 18:07
  • Just what I was looking for! StackOverflow always AWESOME! Thanks anonymous webdev. You make the world a better place. – Leniel Maccaferri Jun 20 '14 at 17:28
1

it came down to a hiddenfield (hiddenfor). I had a date that was being hidden on the page for the model on postback. Chrome doesn't like to play nicely when it is not in america! I ended up having to put this in my web.config

 <system.web>
      <globalization culture="en-GB" uiCulture="en-GB"/>

Once my Thread.CurrentThread.CurrentUICulture was set correctly things played nicely.

Jon
  • 15,110
  • 28
  • 92
  • 132