0

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)" />

1 Answer 1

1

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.