user2587454
user2587454

Reputation: 913

start form validation only on submit

my form is starting the validation (with this plugin) the minute user start typing. for example if i have password input and retype password input, when typing the first character on password it immediately show 'password mismatch' but the user didn't have the chance to type the retype password.

how do i disable the validation on typing and only show errors when the user click on submit? are there any options?

BUT, username with remote check i do want it to show the error when the input if out of focus

$('#frm_user_details').formValidation('validate');

$('#frm_user_details').formValidation({
            framework: 'bootstrap',
            fields: {
                register_first_name: {
                    validators: {
                        notEmpty: {
                            message: 'Please enter your first name'
                        }
                    }
                },
                register_last_name: {
                    validators: {
                        notEmpty: {
                            message: 'Please enter your last name'
                        }
                    }
                },
                username: {
                    validators: {
                        notEmpty: {
                            message: 'Please enter a username.'
                        },
                        remote: {
                            type: 'POST',
                            url: '/core/services/validator.php',
                            message: 'That username is already taken.',
                            delay: 500
                        }
                    }
                },
                register_password: {
                    validators: {
                        notEmpty: {
                            message: 'The password is required and cannot be empty'
                        },
                        identical: {
                            field: 'register_password_retyped',
                            message: 'The password and its confirm must be the same'
                        }
                    }
                },
                register_password_retyped: {
                    validators: {
                        notEmpty: {
                            message: 'The confirm password is required and cannot be empty'
                        },
                        identical: {
                            field: 'register_password',
                            message: 'The password and its confirm must be the same'
                        }
                    }
                },

            },
            onError: function(e) {
                e.preventDefault();
                $('#create_account').removeClass('button-disabled');
            },
            onSuccess: function(e) {
                e.preventDefault();
                $('#create_account').addClass('button-disabled');
                    THIS.services.submitHandler();
                }
            }
        });

Upvotes: 0

Views: 1702

Answers (2)

GuyS
GuyS

Reputation: 1

Just to complete the answer of @Shershen, the "disabled" should be used with 'disabled'. Just a small detail.

$(document).ready(function() {
    $('<your_selector>').formValidation({
        live : 'disabled'
    });
});

Upvotes: 0

shershen
shershen

Reputation: 9993

Here in API docs describing Settings object structure it's mentioned : live property should be to disabled to prevent validation on user typing. - Disable the live validating. The error messages are only shown after the form is submitted

$(formSelector).formValidation({
    live : disabled,
   //other properties

Upvotes: 1

Related Questions