SweetAlert2 - кнопка подтверждения отключения Swal при открытии - PullRequest
0 голосов
/ 04 марта 2020

Я хочу, чтобы кнопка подтверждения была отключена по умолчанию, и выполнить несколько проверок, прежде чем я удалю отключенный статус. Как я могу это сделать?

Текущий код:

Apply: function (el) {
    let id = $(el).data('id');
    let url = $(el).data('url');
$.ajax({
    url: url+'/apply/'+id,
    method: 'GET',
    cache: false,
    success: function(response) {
            // disableConfirmButton
        const swalWithBootstrapButtons = Swal.mixin({
            customClass: {
                confirmButton: 'btn btn-success ml-2',
                cancelButton: 'btn btn-danger'
            },
            customID: {
                confirmButton: 'swal-submit'
            },
            buttonsStyling: false,
        });

        swalWithBootstrapButtons.fire({
            title: 'Apply For Job',
            html: response,
            showCancelButton: true,
            confirmButtonText: 'Apply',
            cancelButtonText: 'Cancel',
            reverseButtons: true,
            onOpen: function () {
                console.log(this);

            },

            preConfirm: (result) => {

                let form     = $('#apply-job-dialog').find('form');
                let action   = form.attr('action');
                let formData = form.serializeArray();

                return $.ajax({
                    url: action,
                    method: 'POST',
                    cache: false,
                    data: formData,
                    success: function(response) {
                        if (response.errors) {
                            Swal.showValidationMessage(response.errors.name);
                        } else {
                            window.location.href = '/jobs/' + id;
                        }
                    },
                    fail: function(xhr, textStatus, errorThrown){
                        console.log(xhr);
                    }
                });
            }
        }).then((result) => {
            if (result.value) {
                // swalWithBootstrapButtons.fire(
                //     'Updated!',
                //     'Your have applied for a job.',
                //     'success'
                // );
            } else if (
                /* Read more about handling dismissals below */
                result.dismiss === Swal.DismissReason.cancel
            ) {
                swalWithBootstrapButtons.fire(
                    'Cancelled',
                    'Data is unchanged',
                    'error'
                );
            }
        });
    },
    fail: function(xhr, textStatus, errorThrown){
        console.log(errorThrown);
    }
});

},

...