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

85
Visualizações
Javascript function going into endless loop

I have a Javascript function that checks if the datatype of the use input is same as that expected by the control e.g. if a character has been entered in an integer field expected in textbox control. The validation message is displayed correctly but the alert does not go away and the function seems to be going into an endless loop. Any help would be appreciated..

Function is as given below :

public ValidateControl(event: Event, dataType: string) {
    let isValid = true;

    let objControl = event.target as HTMLInputElement;
    let elementId = objControl.id;
    let ctrlValue = objControl.value;

    if (ctrlValue.trim() != '') {
      isValid = Common.ValidateDataType(ctrlValue, dataType);
      if (!isValid) {
        document.getElementById(elementId).focus();
        alert("Check your entry in '" + dataType + "' data type column");
        
      }
    }
  }

<div *ngIf="head.ControlType == 'TextBox'">
<input (blur)="ValidateControl($event, head.DataType)" />
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You focus then loose the focus with the alert here which triggers the blur

document.getElementById(elementId).focus();
alert("Check your entry in '" + dataType + "' data type column");

Perhaps reverse those statements order

alert("Check your entry in '" + dataType + "' data type column");
document.getElementById(elementId).focus();
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