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 ;)

3
  • How do you know it doesn't work when all you can type are numbers anyway ? Commented Nov 21, 2013 at 16:26
  • 3
    See fiddle .type="number" is using HTML5 validation not jQuery Validation plugin. fiddle with type="text" uses jQuery Validation Commented Nov 21, 2013 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'.. Commented Nov 21, 2013 at 16:29

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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! :)
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.