Page 1 of 1

Field with varying length data triggering javascript to run

Posted: Tue Oct 15, 2019 2:32 pm
by josephrogers
Mobile responsive

I am still learning and need some help.

The field is 15 alpha in size. The user might scan in 8 bytes of data into it but it does not trigger the onchange element because it did not fill all 15 bytes of the field. How can I run the javascript if the field is not completely filled . I was thinking of maybe using the oninput element but I do not know this would work if the user has to type in the data into the field.

Basicly I need to run a "pui.click();" no matter what amount of data is scanned in or entered into the field if it does not fill the field.

Re: Field with varying length data triggering javascript to run

Posted: Tue Oct 22, 2019 4:47 pm
by matt.denninghoff
If you have the "oninput" event setup on a textbox, then typing into the field or pasting or other inputs that change the value of the field will fire the event.

The "onchange" fires only once the field loses focus--e.g. the user clicks or tabs somewhere else.

Reference: https://www.w3schools.com/jsref/event_oninput.asp

Re: Field with varying length data triggering javascript to run

Posted: Tue Oct 29, 2019 6:35 am
by josephrogers
The issue becomes how does profound know that user has completed inputting the data. Onchange triggers the javascript when field is filled. If the size of the data varies that is being scanned into the element and you want it to process without user hitting enter or tabbing.

I think oninput would be triggered every time user enter each keystroke. Is this right? I would like to use oninput but I think users will have trouble typing in the data.

Re: Field with varying length data triggering javascript to run

Posted: Tue Oct 29, 2019 11:33 am
by DanD
I realize that this is for mobile - if the data is being scanned via a hand-held scanner (or mobile device's camera), perhaps the scanner can be programmed to put in a delimiter of some sort at the end of the input. When that delimiter is hit, process the js.

The thing that really confuses me is that since this is varying, how does the page know when the user is done typing? If the fields had a "rule" in them that the data was to have a format such as <alphadata>-xx where there are "ALWAYS" two characters after the -, it would be fairly simple.

The "simplest" solution that I can think of is to have an onblur event on the input field - however, this would require the user to hit TAB (which you don't want to do) or touch another input area on the screen.

Also keep in mind this pui.click() will return control back to your program - if you want to execute js, wouldn't you want to do that in lieu of pui.click() ?

Good luck

Re: Field with varying length data triggering javascript to run

Posted: Fri Nov 01, 2019 5:57 pm
by Scott Klement
On greenscreen, you'd typically configure the scanner to act as a keyboard. It'd input keyboard codes the same as you would when typing, so the screen has no way to know whether it is a scanner or an actual user pressing keys. In that scenario, you can usually configure the scanner to send the ENTER key after typing in the barcode, which allows the screen to be submitted without filling the entire field.

On more modern displays, I prefer to avoid the keyboard entry way of doing things for the very reason that it doesn't know that the input is a scanner.

Its hard to know how this is done with your particular scanner, since I don't know what that is... so I can't tell you how it works.

but with the ones I've used, they don't just put data into the field as keyboard input. They fire a JavaScript event, and that event gets the scanned barcode passed as a parameter. The data doesn't go into a screen field unless you write code in JavaScript to insert it into the field. If you do that, you can easily also insert code to submit the screen. Or, of course, you could do other things -- such as never put the data on the screen to begin with, but just go ahead and process it.

This more modern approach is also better because it does not rely on the focus already being in a specific place when the event is fired. Since you're setting the value of the field in your own code, you can specify exactly where it goes.