Showing posts with label sweetalert. Show all posts
Showing posts with label sweetalert. Show all posts

Saturday, December 19, 2020

SweetAlert 2 - Option to not focus previous element | Focus another input element rather then previous focused element Swal.fire

This particular post is to focus any other input rather last focused element/input when sweet alert closed. By default sweet alert focused last focused element when alert closed.
let _this = {};
Swal.fire({
    icon: 'error',
    title: 'Oops...',
    text: "Something went wrong",
    didDestroy: function () {
        if(_this.isConfirmed) {
            $("#name").focus();
        }
    }
}).then((result) => {
    _this = result;
});