Prompt using Sweet Alert Library

<!DOCTYPE html>
<html>
<head>
    <title>Sweet Alert Example</title>
</head>
<body>
    <!-- Button to trigger the Sweet Alert -->
    <button onclick="showSweetAlert()">Show Sweet Alert</button>


    <!-- Include SweetAlert JS -->
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.1.4/dist/sweetalert2.all.min.js"></script>
    <script>
        function showSweetAlert() {
            Swal.fire({
                title: 'Enter your name:',
                input: 'text',
                showCancelButton: true,
                confirmButtonText: 'OK',
                cancelButtonText: 'Cancel',
                inputValidator: (value) => {
                    if (!value) {
                        return 'Please enter your name';
                    }
                }
            }).then((result) => {
                if (result.isConfirmed) {
                    const name = result.value;
                    if (name != 'test') {
                       alert("enter valid value")
                   }
                }
            });
        }
    </script>
</body>
</html>

The above code can be implemented in Suite Script as well.

Leave a comment

Your email address will not be published. Required fields are marked *