imknight
7/27/2013 - 10:28 AM

custom function for Parsley before submit

custom function for Parsley before submit

$('#contactform').parsley({
    //exclude input type , file ?
    excluded: 'input[type=hidden]',
    validators: {
        // for #3 ,checking the input must have value , example dropdown list with "Select this" kind of option should be no value so that it can be skipped
        checkdefault: function (val, checkdefault) {
            if (val[0] === '') return false;
            else return true;
        }
    },
    messages: {
        checkdefault: "This value should be a multiple of %s"
    },
    listeners: {
        onFieldValidate: function (elem) {
            //for #2 ,checking and make sure the parent div is not hidden
            if (elem.parents('div.ishidden:eq(0)').length > 0 && !elem.parents('div.ishidden:eq(0)').is(':visible')) {
                return true;
            }

            return false;
        },
        onFormSubmit: function (isFormValid, event, focusedField) {},
        onFieldError: function (elem, constraint) {}
    }
});