Edit File: notify.blade.php
<script> $(document).on('click', '.mail', function(e) { $('.notify_id').val($(this).data('id')); }); $(document).on('click', '.notify', function(e) { $('.notify_id').val($(this).data('id')); }); function resetForm() { $(".text-danger").remove(); // Remove existing error messages $('.store input').removeClass('border-danger'); // Remove border-danger class from inputs $('.notify-form')[0].reset(); // Reset the form inputs } $(document).ready(function() { // Reset the form when the cancel button is clicked $('.cancel-button').on('click', function () { console.log('cancel'); resetForm(); // Call resetForm function }); // Or reset when closing the popup $('.model-notify').on('hidden.bs.modal', function () { resetForm(); // Call resetForm function }); $(document).on('submit', '.notify-form', function(e) { e.preventDefault(); var url = $(this).attr('action'); $.ajax({ url: url, method: 'post', data: new FormData($(this)[0]), dataType: 'json', processData: false, contentType: false, beforeSend: function() { $(".send-notify-button").html( '<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>' ).attr('disabled', true); }, success: function(response) { resetForm(); // Reset validation messages on success $(".send-notify-button").html("{{ __('admin.send') }}").attr('disabled', false); Swal.fire({ position: 'top-start', icon: 'success', title: '{{ __('admin.send_successfully') }}', showConfirmButton: false, timer: 1500, confirmButtonClass: 'btn btn-primary', buttonsStyling: false, }); setTimeout(function() { window.location.reload(); }, 1000); }, error: function(xhr) { $(".send-notify-button").html("{{ __('admin.send') }}").attr('disabled', false); resetForm(); // Reset validation messages on error // Handle validation errors $.each(xhr.responseJSON.errors, function(key, value) { var inputElement = $('.store input[name=' + key + '], .store select[name=' + key + '], .notify-form textarea[name=' + key + ']'); inputElement.addClass('border-danger'); inputElement.after(`<span class="mt-5 text-danger">${value}</span>`); }); }, }); }); }); </script>
Back to File Manager