0

How can I disable or enable my following validation using a button? the pageload loads the following function, I'm not sure how can I unload it.

    $(document).ready(function() {
        //* regular validation
        gebo_validation.reg();
});

    //* validation
    gebo_validation = {
        reg: function() {
            reg_validator = $('.form_validation_reg').validate({
                onkeyup: false,
                errorClass: 'error',
                validClass: 'valid',
                highlight: function(element) {
                    $(element).closest('div').addClass("f_error");
                },
                unhighlight: function(element) {
                    $(element).closest('div').removeClass("f_error");
                },
                errorPlacement: function(error, element) {
                    $(element).closest('div').append(error);
                },
                rules: {     
                        campaign_name: {
                                require_from_group: [1, '.span8'],
                                minlength: 3,
                                //notBoth: ['input[name="exist_campaign_name"]']
                        },
                        exist_campaign_name: {
                                require_from_group: [1, '.span8'],
                                minlength: 3,
                                //notBoth: ['input[name="campaign_name"]']
                        },
                },
                invalidHandler: function(form, validator) {
                    $.sticky("There are some errors. Please correct them and submit again.", {autoclose : 5000, position: "top-right", type: "st-error" });
                }
            });

            $('.span8').on('blur', function () {
                if ($(this).val() != '') {
                    $('.span8').not(this).prop('disabled', 'disabled');
                } else {
                    $('.span8').not(this).removeProp('disabled');
                }
            });

            //Some extra validation methods.
            /* jQuery.validator.addMethod('notBoth', function (value, element, param) {
                return ((value != '') && ($(param[0]).val() == '') || (value == '') && ($(param[0]).val() != ''));
            }, "Please do not fill out both fields"); */    
        }
    };
2

1 Answer 1

0

I've found the solution here.. jQuery validate - set conditional rules based on user selection

Using sample code:

$('#myform').validate({
    rules: {
        fieldA: {
           required:'#checkA:checked'
        }
    }
});
Sign up to request clarification or add additional context in comments.

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.