Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap validator reset form not working

I am trying to reset the form using bootstrap validator

When i click on reset, its removing the input values, but when i click submit even when the input is empty, its still submitting, when it should be showing an error

Here is the js

    $('#shortener').bootstrapValidator({
        container: '#sstatus',
        fields: {
            url: {
                validators: {
                    notEmpty: {
                        message: 'Enter a url!'
                    },
                    uri: {
                        message: 'URL is not a valid url, include http://'
                    }
                }
            }
        }
    }).on('success.form.bv', function(e) {
            // Prevent form submission
            e.preventDefault();

            console.log('in');

            // Get the form instance
            var $form = $(e.target);

            // Get the BootstrapValidator instance
            var bv = $form.data('bootstrapValidator');

            // Use Ajax to submit form data
            $.post('ajax/new_url.php', $form.serialize(), function(result) {

                console.log('works'+result.message);

                $('#shortener').fadeOut('fast', function(){
                    $form.bootstrapValidator('resetForm', true); 
                });

                $(document).on('click', '#shorten_again', function(e){
                    e.preventDefault();
                });

            }, 'json');
    });
like image 746
Daniel Le Avatar asked Nov 22 '22 06:11

Daniel Le


1 Answers

$('form').bootstrapValidator('resetForm', true);

like image 72
user1537143 Avatar answered Feb 25 '24 07:02

user1537143