12

I know that, if I have an input within a <form> element, I can simply add the novalidate attribute to the form to disable the HTML validation tooltips. However, my input is not in a form element (I am using AngularJS and I use the ng-form directive).

I can listen to the invalid event and prevent submit validation, but I cannot prevent validation tooltips.

Here is a simple JSFiddle to show the issue.

2
  • Why do you have the required attribute if you don't really care about the field validating? Commented Aug 10, 2017 at 18:39
  • @ScottMarcus, I handle it with angular validation with my customized tooltips. Commented Aug 10, 2017 at 18:43

3 Answers 3

15

Although Dekel's answer does the job, another way how this could be done is by simply adding a 'title' attribute to the input element, and the validation message will be overwritten with the content in title attribute.

You can add some meaningful text in the title attribute,

<input type="email" title="Your Email"> 
Sign up to request clarification or add additional context in comments.

Comments

9

In HTML you have two options for input elements:

  1. Put them inside a <form> container.
  2. Add the form attribute to the input, the value should be the id of the form that the input is related to.

Using option #2 you can just add an empty form with the novalidate somewhere in your DOM and attach the input to that form:

<form novalidate>
  <p>Input in form with novalidate. This one is fine.</p>
  <input type="email" required>
</form>

<p>Input without form. How to disable validation tooltips? (hover over input to see validation tooltip)</p>
<input type="email" required form="novalidatedform">

<form id="novalidatedform" novalidate />

More information regarding the input element in MDN website.

2 Comments

Surprisingly adding form attribute in input elements worked perfectly in angularJS framework. As I mentioned in the question, I am using ng-form directive to handle validation in angular way. Adding form attribute to inputs did not break angular validation while it prevents HTML5 validation. Tested in Chrome, Firefox, IE 10+. Thanks a lot.
the "angular way" is to use <form name="myform"> and the inputs inside there, then you will have access to the formController from $scope.myform ej. $scope.$myform.$valid
4

You can also use this script

<script>
    document.getElementById( "inputId" ).addEventListener( "invalid",
        function( event ) {
            event.preventDefault();
        });
</script>

Comments

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.