I am using lit-html library to render the data into the form.
The program should auto fill the product name upon inputting the product number. I have written the code but I am unable to auto fill the product name field. For the product name, I have used static dummy data within my JavaScript code.
Is there a way to do this using only web components or using library 'lit-html'?
Below you can find my code
import {html, render} from 'lit-html'
class MyApp extends HTMLElement {
constructor() {
super()
this.attachShadow({mode: 'open'});
const forms = () => {
const productNum = new Array();
const productName = new Array();
productNum[0] = 123;
productName[0] = 'Paper';
productNum [1] = 500;
productName[1] = 'Laptop';
function details(products) {
if (products > 50) {
for (let i = 0; i < productNum.length; i++) {
if (products == productNum[i]) {
this.info.product.value = productName[i]
} else {
this.info.product.value = ''
}
}
}
}
return html` <form name = 'info'>
<input type="text" name="product" onkeyup="${details(parseInt(this.value, 10))}" maxlength=3>ProductNum
<input type="text" name="productName" onkeyup="">ProductName
</form>`
}
const template = html`
${forms()}`
render(template, this.shadowRoot)
}
}
window.customElements.define('my-app', MyApp)