BlairHippo
BlairHippo

Reputation: 9658

parsley.js wrong data-type

I have a form that's being validated by parsley, but parsley seems to be screwing up. The element in question is defined like this:

<input class="num-selector" type="tel" name="gift_amount" data-min="20" data-type="digits" required>

However, stepping through the debugger reveals it's being validated as data-type="phone", which causes validation to fail. (Unless somebody is buying a gift certificate worth over a billion dollars, but that's clearly a fringe condition.)

Has anybody heard of anything like this -- parsley screwing-up the data-type? Ever run into code that picks a fight with parsely.js and corrupts its data like this?

Upvotes: 0

Views: 448

Answers (1)

antyrat
antyrat

Reputation: 27765

The problem is because you use type="tel" in your input and parsley automatically recognizes it as phone number, not digits. Should be:

type="number"

Or just text.

Also there is no such attribute as data-type, you should use data-parsley-type="digits" instead. Same with data-min should be just min or data-parsley-min="20"

So your code can be:

<input class="num-selector" type="text" name="gift_amount" data-parsley-min="20" data-parsley-type="digits" required>

Look at the Validators list on official documentation.

Upvotes: 1

Related Questions