forms field reads from barcode scaner

I have a simple form with Charfield and a barcode scanner as input devices that accept EAN128. The scanner theoretically doesn’t send data if the EAN is correct. I’ve only checked if there are 16 digits in the EAN; sometimes, very randomly, I get 15 digits or only 8. Some times I get the first 8 or, for example, 15 digits, but the missing digit should be in the middle of the EAN. I noticed that the frequency of erroneous readings depends on the computer, scanner model, and browser. Works best on the Edge.
I also tested the solution with just JS + AJAX as passing to the backend, omitting the Django form validation, with no effect.
But I’ve testes both solutions in Sellenium and works perfekt. I think it’s some problem with speed but not shure.
For now, the only thing that works is to set the scanner to continuous mode with the ability to read the same code. But it is a bit of a pain, and the scanner sends EAN at a high frequency (every 1 s).

Is there any proven technique for handling scanners?

For clarification - this is something you’re trying to do in the browser using JavaScript?

I tried two methods

  1. Django form with charfield and validate max/min length. I thought maybe he was losing data from the scanner because he was doing form validation in the backend (django) and he couldn’t hear the scanner during that time
  2. The second way html, javascript and data exchange via ajax with in javascript verification before ajax whether there are 16 characters.
    And both have the same effect with a single reading of the code by the scanner. Often there are missing data.

Ok, but what is actually reading / accepting data from the scanner? How is the data from the scanner getting into the form?

A Django form is just html as it exists in the browser, I’m not understanding what is happening where here.

Skaner reads EAN128 and is connected to the computer by usb he acts like keyboard in theory. I’ve 3 different models and when I measure the time from receiving the first character to the last one, it turned out that two of them have an avg of 60ms and the third one of 120ms. (only valid 16 characters) And the third one obviously has this problem less.
It looks very wird but here discussion scanners it’s old but main idea is that’s the scanners are faster than fingers and this makes different.
I use this snippet from the end of this discussion in my second way.
I was hopping maybe something new become in this field. I find some libs in js in github but old and with issues.

Either way, this isn’t a Django issue. Django doesn’t have any direct involvement in what happens within the browser.

I agree it looks like webbrowser problem. But how this exactly works. For example django form name charfield with some sort of validation. If we put string in input box on web nothing happens? I mean in web code there is <input and some widget setup required, autofocus etc. > in this point if we change to only integers webbrowser block letters without sending to django so something is working. After Enter if webbrowser(html) is ok form is send to backend and we do if form.is_valid() and this is django part. Am I correnct? And after form validation webpage is generated again. It means there are some points in this process where some threads are interrupt? Mey’be that’s the main problem when “quick devices” sending data. Some jobs in webbrowser (checking input data) and sending data to validation interrupt input process.

Nothing happens within Django, correct.

A browser makes a request. Django sends a response (typically html). Once that response has been sent, Django has no further involvement until the next request is made.

Not on it’s own, no.

If a complete form is submitted, then Django is going to return a new page, but there is no handling by Django of an individual field in the browser.

When you’re talking about data type validation of an input field, that’s being done by the browser, not by Django.

After few days fight :slight_smile:
For future. My scanner send “Enter” after msg as terminator and I don’t know why some times this Enter comes between chars and begin form requests to backend.
After reconfiguration - terminator set for F12 everything looks ok all chars are in form.
Thanks KenWhitesell