0

I will be creating a sharepoint used to track inventory. The users will be able to scan a barcode of an item, and have that item automatically recorded as "existing." This would be a basic text box and "submit" button. The user may also type in the number if no scanner is available.

When scanning, I want to avoid requiring the user to click the button after scanning. My idea is to design the barcodes so that there is a "flag sequence" of characters that will indicate to sharepoint that the data entered was from a barcode (and not manually typed in). Then I can detect when the textbox contents change, if the "flag sequence" is at the end, and automatically click the button for the user. If the "flag sequence" is not there, then it is because the user is typing in the number by hand, and therefore the button will not be automatically clicked.

Is this possible? Is there a better way to do it? I don't have the ability to program the scanner to include a carriage return.

1 Answer 1

2

I just did this for another list. I used the code found in this stack overflow question Scan barcode into textbox

This uses timing and a minimum length to determine if the barcode is through a wand, hand entered, or has a carriage return. It auto focuses the page to the text field, then the code listens to that field for a keypress, or loss of focus. It's quite involved but it works great - thanks to the person who posted it.

I put the code in a CEWP on the form. Here is part of it

// handle a key value being entered by either keyboard or scanner
$("#fmgItem").keypress(function (e) {
    // restart the timer
    if (timing) {
        clearTimeout(timing);
    }

    // handle the key event
    if (e.which == 13) {
        // Enter key was entered

        // don't submit the form
        e.preventDefault();

        // has the user finished entering manually?
        if ($("#fmgItem").val().length >= minChars){
            userFinishedEntering = true; // incase the user pressed the enter key
            inputComplete();
        }
    }
    else {
        // some other key value was entered

        // could be the last character
        inputStop = performance.now();
        lastKey = e.which;

        // don't assume it's finished just yet
        userFinishedEntering = false;

        // is this the first character?
        if (!inputStart) {
            firstKey = e.which;
            inputStart = inputStop;

            // watch for a loss of focus
            $("body").on("blur", "#fmgItem", inputBlur);
        }

        // start the timer again
        timing = setTimeout(inputTimeoutHandler, 500);
    }
});
1
  • This is exactly what I was looking for - great cross-site find!
    – Michael
    Sep 7, 2017 at 19:56

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.