HTML5 is only valid for some inputs

I have a very simple question - is there a way to disable HTML5 validation for only some selected inputs (instead of setting "novate" for the entire form)?

I mean something like <input type='number' required

novalidate >

. But it doesn't work.

You may ask why I need type = "number" or "required" then? Well, I need it because my framework uses it for its own validation.

EDIT

This is one special entry - birth number. I need it to be a type number (due to mobile devices), but its value is mostly used with "/" (eg 860518/8757) which is not a valid character for a type number. So I need the user to fill it in without the forward slash (8605188757). The problem is that an invalid value populated by the html5 input (like "fsda" in the number type) appears to be empty with no value.

So when the user fills in a value in the wrong format (860518/8757), html validation is disabled, so JS validation is done, it is validated as an empty field. So the error message is like "Please fill in the birth number of the field" (which is really confusing) instead of somthing like "Sorry, wrong format".

My solution was to enable html5 validation for this field (so the browser message is displayed by default when the wrong format is filled in), but disable it for other fields so that they are only validated with my JS validation.

+3


source to share


2 answers


novalidate

the attribute is only for the form tag, it cannot be applied to format controls.

You can remove the required attribute in js after your framework checks:



$('[Selector]').removeAttr('required');​​​​​

      

Now the selected field will not be validated.

0


source


If you want to remove validation on one element, you can use formnovalidate

in your input element. for example

<input type="submit" value="Save" class="button primary large" formnovalidate/>

      



For more information go here .

0


source







All Articles