Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

211
Views
How do I pass through text inputted in SweetAlert2 box to a .then method?

Right now I am doing the following:

function resetPassword(email) {
    /* The following is for the alert dialog box that is triggered when the user 
    presses forget password! */
    
    Swal.fire({
        title: 'Enter the email address',
        input: 'text',
        inputAttributes: {
            autocapitalize: 'off'
        },
        showCancelButton: true,
        confirmButtonText: 'Send Reset Email',
    }).then((input) => {
        firebase.auth().sendPasswordResetEmail(email)
        .then(() => {
            Swal.fire({
                title: 'Email Sent!',
                text: 'Check your email for a reset link!',
                type: 'success',
                confirmButtonText: 'Cool'
            });
        })
        .catch((error) => {
            Swal.fire({
                title: 'Error!',
                text: error.message,
                type: 'error',
                confirmButtonText: 'Cool'
            });
        });
    });
}

But it is not working, what am I doing wrong?

My main outcome is to get the email, pass it through to firebase auth api, send the email, then put one more diag box out that says "done" basically. But the input is not coming through. Why is this?

Thanks in advance.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

The Swal result will be stored in an object with the same name that you define in the passed parameter to the 'then' function, in this case, input. The email address is stored in input.value. I'd also remove the unnecessary email parameter from the function declaration. This should work:

function resetPassword() {
    /* The following is for the alert dialog box that is triggered when the user 
    presses forget password! */
    
    Swal.fire({
        title: 'Enter the email address',
        input: 'text',
        inputAttributes: {
            autocapitalize: 'off'
        },
        showCancelButton: true,
        confirmButtonText: 'Send Reset Email',
    }).then(({value: input}) => {
        firebase.auth().sendPasswordResetEmail(input)
        .then(() => {
            Swal.fire({
                title: 'Email Sent!',
                text: 'Check your email for a reset link!',
                type: 'success',
                confirmButtonText: 'Cool'
            });
        })
        .catch((error) => {
            Swal.fire({
                title: 'Error!',
                text: error.message,
                type: 'error',
                confirmButtonText: 'Cool'
            });
        });
    });
}
about 4 years ago · Juan Pablo Isaza Report

0

Thank you for your answer @Chris, but after yours not working I then went onto the SA2 docs and found a login page, then heavily modified it to the following:

function resetPassword() {
    /* The following is for the alert dialog box that is triggered when the user 
    presses forget password! */
    
    Swal.fire({
        title: 'Please Enter Your Email Address',
        html: `<input type="text" id="email" class="swal2-input" placeholder="mail@website.com">`,
        confirmButtonText: 'Sign in',
        focusConfirm: false,
        preConfirm: () => {
            const email = Swal.getPopup().querySelector('#email').value
            return { email: email }
        }
    }).then((result) => {
        firebase.auth().sendPasswordResetEmail(result.value.email)
    .then(() => {
        Swal.fire({
            icon: 'success',
            title: 'Email Sent!',
            text: 'Check your email for a reset link!',
            type: 'success',
            confirmButtonText: 'Cool'
        });
    })
    .catch((error) => {
        Swal.fire({
            title: 'Error!',
            text: error.message,
            type: 'error',
            confirmButtonText: 'Cool'
        });
    });
});
}

Thanks for your help though and the solution which I am posting now did take a long time to make so you are still greatly appreciated.

Have a nice day!

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!