I've created a web application that requires the user to input a product number. Adjacent to the input field is an arrow icon that the user clicks. Upon clicking, there is validation to ensure that the entered number matches one of the valid product numbers stored in an array. If it's a match, a div containing information related to that product should be displayed and populated.
If the user enters the same number again and clicks the arrow, the same div should appear beneath the existing one. If a different valid number is entered, a new div with the corresponding product info should show up below the previous div. In case of an invalid number entry, an error message indicating the invalid input should be displayed without generating another div.
Currently, I'm using a show-hide method in my HTML file to display or hide the div based on the validity of the input number. However, I would like to generate multiple divs if the number is valid (as shown in the transactionDetails div below). I am wondering how I can achieve this functionality?
Below is a snippet of my HTML code:
<input class="numberInput" formControlName="ProductNumber" type="number" placeholder="{{'EnterNumber' | translate}}" [ngClass]="displayErrors ? 'inputRedBorder': 'input'" style="width:150px !important;"/>
<span (click)="validateNumber()">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 8 8" style="vertical-align: middle;">
<path d="M5 0v2h-5v1h5v2l3-2.53-3-2.47z" transform="translate(0 1)" />
</svg>
</span>
<div class="transactionDetails grid" *ngIf="showResults">
<!-- Product details here -->
</div>
And here's my validate function:
listOfValidProductNumbers = [
3097165,
6100256,
6124380,
2177422,
3795377,
6097961,
3808804,
6110164,
1705466];
validateSKU()
{
const productNumber = this.transactionForm.get('ProductNumber').value;
if (this.listOfValidProductNumbers.indexOf(productNumber) > -1 ) {
this.showResults = true;
} else {
this.showResults = false;
}
}