I tried with QuaggaJS for check barcode type using barcode number but its not working.
<div class="form-group">
<div class="label-mini"><span>Barcode</span></div>
<input
nz-input
placeholder="Product Barcode*"
name="product_barcode"
formControlName="barcode_number"
/>
</div>
<div class="form-group">
<div class="label-mini"><span>Select Barcode Type</span></div>
<nz-select
nzPlaceHolder="Barcode Type"
name="barcode_type"
formControlName="barcode_type"
>
<nz-option nzValue="code128" nzLabel="CODE128"></nz-option>
<nz-option nzValue="EAN14" nzLabel="EAN14"></nz-option>
<nz-option nzValue="code39" nzLabel="CODE39"></nz-option>
<nz-option nzValue="EAN8" nzLabel="EAN8"></nz-option>
<nz-option nzValue="msi" nzLabel="MSI"></nz-option>
</nz-select>
</div>
here I have two input field as barcode_number and barcode_type I want if I type any barcode_number
it will automatically detect the barcode_type
tried Quagga:
Quagga.onDetected((result) => {
const detectedBarcode = result.codeResult.code;
this.stockForm.get('product_barcode').setValue(detectedBarcode);
this.barcodeInput.nativeElement.value = detectedBarcode; // Update the barcode input value
// Automatically select the most similar known barcode type
const detectedType = result.codeResult.format;
console.log("result: ", result)
console.log("detectedBarcode: ", detectedBarcode);
console.log("detectedType: ", detectedType);
let similarity = 0;
let mostSimilarType: string | null = null;
for (const knownType of this.knownBarcodeTypes) {
const similarityScore = this.compareBarcodeTypes(detectedType, knownType);
if (similarityScore > similarity) {
similarity = similarityScore;
mostSimilarType = knownType;
}
}
this.stockForm.get('barcode_type').setValue(mostSimilarType);
this.barcodeInput.nativeElement.dispatchEvent(new Event('change')); // Trigger a change event
Quagga.stop(); // Stop scanning after the first barcode is detected
});
compareBarcodeTypes(detectedType, knownType) {
return detectedType
=== knownType ? 1 : 0; }
nothing is working for me.
I as expect when i type barcode_number it will auto detect the barcode_type and change on select option automatically.