Bootsrap Modal ajax save multiple record, bootstrapValidator

54 views Asked by At

I have problem with bootstrap modal form. For validate fields im using bootstrapValidator. My problem is that when i popup the modal and then close data from inputs are deleted, but when i popup again and fill the fields then send AJAX my script insert to DB multiple records.

<script>
    $(document).ready(function () {
        $(".bs-example-modal-lg").on('hidden.bs.modal', function (e) {
            $("#ModalClientTransportowe").bootstrapValidator('resetForm', true);
        });
    });
</script>

<script>
    $('.bs-example-modal-lg').on('shown.bs.modal', function () {
        $(document).ready(function () {

            $('#ModalClientTransportowe').bootstrapValidator({
                message: 'This value is not valid',
                excluded: [':disabled'],
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    company: {
                        validators: {
                            notEmpty: {
                                message: 'Proszę wprowadzić nazwe klienta'
                            }
                        }
                    },
                }
            });
        }).on('success.form.bv', function (e) {
            e.preventDefault();
            var data = $("#ModalClientTransportowe").serialize();
            $.ajax({
                type: 'POST',
                data: data,
                url: "{{ path('saveClient') }}",
                success: function (data) {
                    $('#hint').val(data);
                    $('.bs-example-modal-lg').modal('hide')
                },
            });
        });
    });
</script>

I think that's the problem is by calling ajax on every show.bs.modal action.

Can someone give advice about how can i do it to work propely ?

1

There are 1 answers

0
Shrewd On

OK, the answer is very simple... i deleted on show event and everythink worked! :)