Skip to content

undefined validator: validate_strength #485

Open
@bewards

Description

@bewards

default and location validators are working fine, but "validate_strength" will not load:

Uncaught Error: Using undefined validator "validate_strength"
image

The input
<input tabindex="1" data-validation="strength" data-validation-strength="2" id="Password" name="Password" placeholder="* Password" type="password">

My config set up

  • The onModulesLoaded callback does not get hit. I have a single form on the page that gets bound.
var Validator = (function() {

    // vars
    var defaultFormClass = 'form',
        clientErrClass = 'err-client',
        errBorderColor = '#ec331a',
        recaptchaClass = '.vca-recaptcha',
        emailCaptureStart = '.email-capture-start',
        emailCaptureEnd = '.email-capture-end';

    //settings
    var globalOptions = {
        showHelpOnFocus: false,
        validateOnBlur: false,
        validateHiddenInputs: true,
        modules: 'location, security',
        borderColorOnError: errBorderColor,
        onModulesLoaded : function() {
            console.log('All modules loaded');
        },
        onElementValidate: function (valid, $el, $form, errorMess) {

            // email capture
            if(valid && $form.closest(emailCaptureStart).length > 0)
            {
                $el.siblings("input[type=submit]").removeAttr("disabled");
            }
            else
            {
                $el.siblings("input[type=submit]").attr("disabled", "disabled");
            }
        },
        onValidate: function ($form) {

        },
        onError: function ($form) {
            $form.addClass(clientErrClass);

            // transform error messages to list
            //alert($form.find('.form-error').length);
            return false;
        },
        onSuccess: function ($form) {
            $form.removeClass(clientErrClass);

            // email capture
            if($form.closest(emailCaptureStart).length > 0) {
                $form.closest(emailCaptureStart).fadeOut(500, function() {
                    $(emailCaptureEnd).fadeIn(500);
                });
                return false;
            }
            return true;
        }
    };

    function setCustomValidators() {
        $.formUtils.addValidator({
            name: 'recaptcha',
            validatorFunction: function (value, $el, config, language, $form) {

                if (typeof window.grecaptcha !== 'undefined') {

                    var widgetId = $form.find(recaptchaClass).data('widgetId');
                    if (typeof widgetId === "undefined") {
                        return false;
                    }

                    var v = window.grecaptcha.getResponse(widgetId);
                    if (v.length !== 0) {
                        return true;
                    }
                    return false;
                }
                return false;
            },
            errorMessage : 'Recaptcha required',
            errorMessageKey: 'recaptcharequired'
        });
    }

    // start
    function init() {

        setCustomValidators();

        $(defaultFormClass).each(function() {
            var $currForm = $(this);

            globalOptions.form = $currForm;
            globalOptions.errorMessagePosition = $currForm.find('.err-client .current-errors');

            // set validator
            $.validate(globalOptions);
        });
    }

    return {
        init: init()
    }
})();

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions