1

I am observing some strange behavior. Under some circumstances including, if I call valid on any of the fields, the way "This field is required" is displayed changes. Why is this happening? Perhaps any kind of error on the page? enter image description here enter image description here

2
  • The [!] is the browser's built-in validation. This field is required comes from jquery-validate. Commented Apr 30, 2015 at 0:38
  • Please show the relevant code. The way the jQuery Validate plugin works, it's impossible to see HTML5 validation popups mixed with jQuery Validate messages on the same form. Commented Apr 30, 2015 at 1:13

1 Answer 1

3

The message This field is required comes from jquery-validate.js, which runs when you call .valid().

The messasge [!] Please select an item in the list comes from the browser's built-in validation when you have the required attribute in the element. It does this check when the form is being submitted.

If you don't want the browser's validation, don't put attributes like required in the HTML. jquery-validate understands class="required", or you can put the specification of which fields are required in the rules when you initialize the plugin:

$("#formid").validate({
    rules: {
        customer: "required",
    }
});
Sign up to request clarification or add additional context in comments.

6 Comments

Thank you, this must be it. I am fairly new to this appreciate your help. I do like the browser default display? What is the preferred/recommended way to do validation? jquery validator or browser? I was mixing them up apparently. Using different validators for different fields ok? I guess look wise not that great...
jquery-validator gives you lots of validation options that the browser doesn't have, including the ability to create custom validation rules. It also provides lots of customization features, so you can provide your own messages, and control how they're displayed. So it depends on how much you want to do.
that is exactly why I added it in a first place. just could not figure out inconsistency. the way messages are displayed are not great of course. Thanks again.
Just to be clear, when using the jQuery Validate plugin, the novalidate attribute is added to the form automatically. In other words, you would only get the HTML5 popup if jQuery Validate is not installed and initialized. Also, the jQuery Validate plugin will automatically handle the required attribute exactly the same as the required class.
@Sparky I forgot about that novalidate attribute. I wonder why he's seeing the built-in message, then. I know that it handles the required attribute, I was just showing how to tell jquery-validate that it's required in a way that the browser won't notice.
|

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.