Ionic: Make the confirm button return to the first form error

Asked

Viewed 33 times

0

Hello, I’m with a project in Ionic/firebase and has in it a form with about 31 questions and need that on this screen to click to finish instead of back to the top as follows in this function that is in the code this.content.scrollToTop(); i need it to return to the first invalid question. NOTE: I have tried many tutorials on the internet . Below is an excerpt from my . TS:

  enviar(abertura: Abertura) {
    if (this.form.form.invalid) {
      let confirmAlert = this.alertCtrl.create({
        title: 'Parece que há alguma questão sem marcar!',
        message: 'Para proseguir, marque o que está faltando!',
        buttons: [
          {
            text: 'Voltar',
            handler: () => {
              console.log('Voltar clicado');
              this.content.scrollToTop();
            }
          },
        ]
      });
      confirmAlert.present();
    }
  • Already tried to focus on invalid element?

2 answers

0

Can use pure HTML with hyperlink follow example:

Create the attribute in your questions

<h2 id="Pergunta1">Pergunta 1</h2>

when you want to navigate to question 1 create a hyperlink dynamically

<a href="#Pergunta1">Pule para pergunta 1</a>

0

Instead of using the function this.content.scrollToTop(), you can use this.content.scrollTo(x, y, duracao). To find the y position of the element, you can use the property offsetTop.

  • In case I would have to put a position x in each question?

  • How do you identify the question that has not been answered? In this function you can identify the element in which to search for offsetTop.

  • got obgd, I’ll tenatr execute the code

Browser other questions tagged

You are not signed in. Login or sign up in order to post.