gidaban79
5 months ago

Remove error message after open second time of modal

Posted 5 months ago by gidaban79

Hello guys,

i am trying to do validation of adding some value to database in modal.

So far validation working well, However when user will press close modal and will open again previously message still is showed.

js script

$('.saveService').on('click', function () {
                    let msg = $('#msg');
                    $.ajax({
                        type: 'PUT',
                        url: '{{route('business.services.store')}}',
                        data: {
                            name: $('#service').val()
                        }, error: function (data) {
                            msg.html(data.responseJSON.errors.name[0]);
                        },
                        success: function (data) {
                            console.log(data);
                        }
                    })
                }
            );

and modal

<div class="modal fade" id="services" tabindex="-1" role="dialog" aria-labelledby="servicesLabel"
         aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="servicesLabel">Add New Service</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    {{Form::open()}}
                    <div class="row">
                        <div class="col-md-12">
                            {{Form::label('service','Service',['class' => 'form-control-label'])}}
                            {{Form::text('service',null,['class'=>'form-control'])}}
                            <div id="msg"></div>
                        </div>
                    </div>
                    {{Form::close()}}
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-warning btn-sm" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-success btn-sm saveService">Save changes</button>
                </div>
            </div>
        </div>
    </div>

Please sign in or create an account to participate in this conversation.