Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

154
Vistas
Angular2 - Enter Key executes first (click) function present on the form

I don't know why each time I press ENTER key in an input element the application execute the first function it finds in the html .

How Can I prevent it ?

I tried to make some test with (keyup.enter) event but it first execute the first (click) function, then the the (keyup.enter) function...

This is the code:

html form

<form role="form" [formGroup]="FormOffertDetail" (keyup.enter)="checkKey()">

<p-dialog modal="modal" [(visible)]="displayModal_Duplicate" width="300" responsive="true">
  <p-header>
    Dupplica Offerta
  </p-header>

  <div class="form-group">
    <label for="idCustomer">Selezionare il Cliente</label>
    <!--<input formControlName="idCustomer" type="text" class="form-control input-sm" id="idCustomer" placeholder="" required autofocus>-->
    <select id="idCustomer_dup" class="form-control" formControlName="idCustomer_dup" [(ngModel)]="idCustomer_dup">
                    <option [value]="c.idCustomer" *ngFor="let c of listCustomers">
                      {{c.businessName}}
                    </option>
                    </select>
  </div>

  <p-footer>
    <div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix">
      <button class="btn btn-primary btn-space" (click)="do_OffertDuplicate()"><i class="fa fa-copy fa-lg" aria-hidden="true"></i> Dupplica</button>
      <button class="btn btn-danger btn-space" (click)="displayModal_Duplicate=false"><i class="fa fa-trash-o fa-lg" aria-hidden="true"></i> Annulla</button>
    </div>
  </p-footer>
</p-dialog>

......

component.ts functions

 do_OffertDuplicate() {
    if (this.idCustomer_dup == null) {
      alert("Selezionare il Cliente");
      return;
    }

    this.offertService.Duplicate(0, this.offert.idOffert, this.idCustomer_dup).subscribe(
      res => {
        this.displayModal_Duplicate = false;
        alert("OFFERTA DUPPLICATA ( "+res.idOffert+" )");
        this.router.navigate(['OffertDetail', res.idOffert]);
        
      }
    );

  }

checkKey()
{
  alert();
}

Thanks to support!

8 months ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Without a type on the button, it is seen as a submit button so it may be attempting to submit the form. Try adding the type to the button tag:

<button
  ...
  type="button"
  ...
>
8 months ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.