ojek
ojek

Reputation: 10078

jQuery validation - int field validation sometimes doesn't work

On my website, I have a form that includes CKEditor, and input field for numeric value. Now, sometimes, when I try to submit form, validator is saying, that numeric input field is not in a proper range. The problem is, that the range is set to 1-1000, and I am setting the value that is within this range. So it is totally ignoring my input and assuming that there is nothing. The main problem with that behavior is, that most of the times this works okay (I mean it is validating correctly). But like 10% of the times, it is doing those weird things, and console is throwing no errors... Has anyone had similar problems?

Is it maybe possible to turn off jquery validation for single input field?

Edit: here is my input field:

<input class="text-box single-line" data-val="true" data-val-number="The field Price must be a number." data-val-range="The field Price must be between 1 and 1000." data-val-range-max="1000" data-val-range-min="1" data-val-required="The Price field is required." id="Price" name="Price" type="number" value="0">

Upvotes: 1

Views: 377

Answers (1)

Travis J
Travis J

Reputation: 82297

Looks like an mvc input to me. I would assume you are using this somewhere: @Html.ValidationFor( m => m.Price ) which you may omit if you wish to remove validation altogether.

If that is not the case, then just remove the data-annotations from the element

<input id="Price" name="Price" value="0" />

However, I think you should also consider allowing the range to be 0-100 or setting the initial value at 1. The reason being that as it stands now if someone clicks submit without making an entry, then the value of the field will be 0, and that will fail the range validation of 1-100.

Upvotes: 1

Related Questions