Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

221
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda