0

I have custom ErrorPlacement function in my validator, which displays error in tooltip:

errorPlacement: function (error, element) {
    var lastError = $(element).data('lastError'),
        newError = $(error).text();
    $(element).data('lastError', newError);
    if (newError !== '' && newError !== lastError) {
        $(element).tooltipster('content', newError);
        $(element).tooltipster('show');
    }
},

This works fine, but I would also need to display "Please, fill in all required fields" message on top of the form.

How can I do that with jQuery Validate?

2 Answers 2

1

Sorry for bad english, You can use bootstrap tooltip for this like that `

   rules: {
        first_name:"required",
    },

    highlight: function (element) {
        $(element).addClass('is-invalid');
    },
    unhighlight: function (element) {
        $(element).removeClass('is-invalid');
        $(element).attr('data-original-title','');
    },
    errorPlacement: function (error, element) {
        element.attr("data-toggle", "tooltip");
        element.attr("data-original-title", error[0].innerHTML);
        error.css({
            'color': '#FF0000',
        });
        $('.is-invalid').tooltip();
        return false;
    },
    messages:{
      first_name:"Please provide first Name."
   }`

In error placement you define and initialize tooltip then in unhighlight you reset tooltip title.

Sign up to request clarification or add additional context in comments.

Comments

0

The option you are looking for is described in the documentation, under errorContainer:

errorContainer Hide and show this container when validating. Example: Uses an additonal container for error messages. The elements given as the errorContainer are all shown and hidden when errors occur. However, the error labels themselves are added to the element(s) given as errorLabelContainer, here an unordered list. Therefore the error labels are also wrapped into li elements (wrapper option).

Code would look like this:

$('form').validate({
    errorContainer:'#myErrorDiv'
});

Working example: http://jsfiddle.net/ryleyb/3cDY4/

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.