2

I've got a form, within an input Html element:

<input name="MyInputName" type="number" />

and its 'type' attribute is set to "number" because I want to take advantage of HTML5's features.

In my js code I initialize jQuery.validate plugin:

$('.myFormClassName').validate({
   rules: {
      MyInputName: {
         digits: true
      }
   }
});

... but it does not work.. I've managed everything correctly: I'm sure of this because if I get off my input's 'type' attribute (or set it to "text"), the validation works fine.

Is it a bug of jQuery.validate plugin or am I carelessly missing something important?

Thanks everyone ;)

Sparky
  • 98,165
  • 25
  • 199
  • 285
andrea.rinaldi
  • 1,167
  • 1
  • 13
  • 33
  • How do you know it doesn't work when all you can type are numbers anyway ? – adeneo Nov 21 '13 at 16:26
  • 3
    See [fiddle](http://jsfiddle.net/cse_tushar/sFzxc/) .`type="number"` is using HTML5 validation not jQuery Validation plugin. [fiddle](http://jsfiddle.net/cse_tushar/sFzxc/1/) with `type="text"` uses jQuery Validation – Tushar Gupta - curioustushar Nov 21 '13 at 16:28
  • I can type numbers.. the 'type' attribute is evaluated when you call the 'submit' function on your form element.. but in some case I can't call the 'submit'.. – andrea.rinaldi Nov 21 '13 at 16:29

1 Answers1

5

This issue has been identified before and was supposedly fixed...

You can read about it here: https://github.com/jzaefferer/jquery-validation/issues/97 and here: https://github.com/jzaefferer/jquery-validation/pull/145

However, it appears others are reporting more recently (the above "fix" is around 2 years old, whereas this issue report is within the past few months) and so it may be broken again: https://github.com/jzaefferer/jquery-validation/issues/922

The only work-around I've found is to use type="text" on the input element. This is unfortunate because then you end up with the plain text input rather than the nice HTML5 integer box.

mason81
  • 1,730
  • 2
  • 18
  • 33
  • 1
    Yeah, after I posted my question on here I read about others having my same issue.. It's a real pity that the only work-around is using type="text". Thanks for the kind answer, man! :) – andrea.rinaldi Jan 02 '14 at 23:37
  • 1
    I agree, it is a real pity. Perhaps they will fix it again at some point. Anyway, thanks for accepting my answer. Best wishes and happy coding. – mason81 Jan 03 '14 at 15:24