Field with varying length data triggering javascript to run

Use this board to ask questions or have discussions with other Rich Displays users.
Post Reply
josephrogers
New User
Posts: 2
Joined: Wed Dec 12, 2018 2:41 pm
First Name: Joseph
Last Name: Rogers
Company Name: Conestoga Woods Specialties
Phone: 7174453419
Address 1: 245 Reading Road
City: East Earl
State / Province: Pennsylvania
Zip / Postal Code: 17519
Country: United States
Contact:

Field with varying length data triggering javascript to run

Post 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.
User avatar
matt.denninghoff
Profound Logic Staff Member
Posts: 115
Joined: Wed Feb 10, 2016 3:53 pm
First Name: Matthew
Last Name: Denninghoff
Company Name: Profound Logic Software
State / Province: Ohio
Country: United States
Contact:

Re: Field with varying length data triggering javascript to run

Post 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
josephrogers
New User
Posts: 2
Joined: Wed Dec 12, 2018 2:41 pm
First Name: Joseph
Last Name: Rogers
Company Name: Conestoga Woods Specialties
Phone: 7174453419
Address 1: 245 Reading Road
City: East Earl
State / Province: Pennsylvania
Zip / Postal Code: 17519
Country: United States
Contact:

Re: Field with varying length data triggering javascript to run

Post 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.
DanD
Profound User
Posts: 42
Joined: Wed Jun 14, 2017 12:06 pm
First Name: Dan
Last Name: Devoe
Company Name: Boston Warehouse Trading
State / Province: Massachusetts
Zip / Postal Code: 02062
Country: United States
Contact:

Re: Field with varying length data triggering javascript to run

Post 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
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Field with varying length data triggering javascript to run

Post 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.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 4 guests