Search code examples
jqueryvalidationjquery-pluginsjquery-validation-engine

How to get function onFieldSuccess for jQuery Validation Engine


I'm using a jQuery Validation Plugin/Engine, called: jQuery.validationEngine.

Posabsolute | jquery-form-validator-because-form-validation-is-a-mess

There is a function called: onFieldSuccess and onFieldFailure but I cant get them to work. This can also come because I'm now doing jQuery for a little while and do not have much experience, so I'm hoping someone here can help me out.

The only diecription on this function is: Description functions onFieldSuccess/onFieldFailure

The normal functions and functionality are working like a charm. What I have now is:

function testing() {
    alert('Fail');

}

$(document).ready(function() {

    jQuery("#login-form").validationEngine('attach', {
        promptPosition: 'topLeft', scroll: true,
            bindMethod: "on",
            ajaxFormValidation: true,
            //onFieldSuccess: testing,
            onFieldFailure: testing,
            onBeforeAjaxFormValidation: before_Login_Call,
            onAjaxFormComplete: ajaxValidation_Login_Callback
    });
    $("#login-form").bind("jqv.field.result", function(event, field, errorFound, prompText){ console.log(field) })

});


Solution

  • I found the problem.

    It's really easy.

    Just set in the core .js file the options like this and you're done:

    onFieldSuccess: true,
    onFieldFailure: true,
    
    addSuccessCssClassToField: 'inputbox-success',
    addFailureCssClassToField: 'inputbox-error',
    

    The two below (addSuccessCssClassToField and addFailureCssClassToField) are the two css classes the will be used when there is an error.

    You can set this in the core .js file or you can override the options when you call the validator.

    Hopes this also helps someone else. If you have a question about this, I'll be happy to help you out.