JQuery Validation Plugin and Tooltipster Plugin Plugin

I am trying to customize the error messages that the user receives using Tooltipster , and I encountered the following problem:

You called the "content" Tooltipster method on an uninitialized element

My HTML is:

<form>
  <input id="one" type="number" name="one" />
  <input id="two" type="number" name="two" />
  <button id="button" type="submit">Submit</button>
</form>

JavaScript:

$(document).ready(function () {

            $('form').validate({ // initialize the plugin
                rules: {
                    one: {
                        required: true,
                        min: 1,
                        max: 100
                    },
                    two: {
                        required: true,
                        min: 50,
                        max: 80
                    }
                },
                submitHandler: function (form) {
                    doTest();
                    return false;
                },
                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');
                    }
                },
                success: function (label, element) {
                    $(element).tooltipster('hide');
                }
            });

        });

What could be the problem?

+4
source share
1 answer

Console Error:

You called the "content" Tooltipster method on an uninitialized element

The problem is that you incorrectly initialized the Tooltipster plugin on your input elements.

// initialize tooltipster on form input elements
$('form input').tooltipster({  // <-  USE THE PROPER SELECTOR FOR YOUR INPUTs
    trigger: 'custom', // default is 'hover' which is no good here
    onlyOne: false,    // allow multiple tips to be open at a time
    position: 'right'  // display the tips to the right of the element
});

See: fooobar.com/questions/290140 / ...

+7
source

Source: https://habr.com/ru/post/1531647/


All Articles