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

0
Hello, I have a project in ionic / firebase and it has a form with about 31 questions and I need it on this screen to click to finish instead of going back to the top as follows in this function that is in code this.content.scrollToTop(); I need him to return to the first invalid question. I've tried many tutorials on the internet. Here 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();
    }
    
asked by anonymous 03.08.2018 / 21:23

2 answers

0

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

    
03.08.2018 / 21:53
0

You can use pure HTML with hyperlink following 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>
    
04.08.2018 / 04:30