Disable native browser validation

Asked

Viewed 293 times

2

Would you like to know how to disable native browser validation in a form? I would just like to leave my validation in Jquery.

What I wanted to take is this text box "Fill in this field.".

Any suggestions? I tried to use novalidate, but it ignore until my validation in Jquery.

inserir a descrição da imagem aqui

1 answer

3


Adds the attribute novalidate à <form>.

This attribute is exactly to tell the browser that the form should not use HTML5 validation.

jsFiddle: https://jsfiddle.net/u0ts0w8k/1/

If you can put the attribute logo in the HTML, otherwise you can do it with Javascript

document.querySelector('form').setAttribute('novalidate', true);
  • And I used this attribute, and it worked. But the problem is that it ignores my validation in Jquery too... I want my Jquery validation to continue working.

  • @Vynstus what is the validation you are using? Can you put an example of the code? You can adapt my jsFiddel maybe to show an example of the problem.

  • At a glance, even with the jquery validation, it runs Submit. https://jsfiddle.net/u0ts0w8k/5/

  • 1

    @Vynstus you have to use .preventDefault(); and you can do this: https://jsfiddle.net/u0ts0w8k/6/ (note that I passed var err = 0; into Event Handler because it needs to be 0 every time you try to make Submit.

  • 1

    Cool! That’s right, thank you!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.