This topic is locked
[SOLVED]

Field-Events/Edit - Barcodescanner : Edit Event fires only if manual edit

5/12/2022 8:18:05 PM
PHPRunner General questions
C
ckranich authorDevClub member

Hi,

I have a Field Event On a TextField which should be filled by barcode scanner.
The field Event is used to validate a barcode number against a SET value (taken from a label in the same ADD form)
if the barcode is equal to the requested number, a checkbox is checked...

PROBLEM:
The validation works OK if barcode numbers are entered manually into field
The validation works OK if barcode scanner suffix is TAB
(Unfortunately they need suffix is ENTER, as they use tha scanner for other applications too)
The Validation fails if barcode scanner suffix is ENTER - It needs a manual DEL at end of string to
become successful. I tried looking for a "\n" at end of string and delete it. But there is none.
It just looks as if the edit Event is not fired if Enter is received.

Any Suggestions?

Kind Greetings,
ckranich

How I tried to implement this

img alt

We have in this Form:
a Field as Text : "MOTIV_CUSTOMER_EAN", RO to show the correct barcode
a Field as Checkbox : "EAN_CODE" This is the actual result of the form and shall not be clickable directly; This is set/cleared according to validation
a Dummy Field as Text : "EAN_SCAN" which is used to scan the barcode using barcode scanner that emulates keyboard.

Field Event (Click) of Checkbox:

var checked; // local variable
// invert action of click -> disable click action
checked = this.getValue();
if (checked == 'on')
{
this.setValue('');
}
else
{
this.setValue('on');
}
return false; // no Step 2 + 3

=> This simply prevents to set the checkbox directly, works OK

Field Event (Edit) of "EAN_SCAN"
function OnBefore()

var ctrlSOLL = ctrl.getPeer('MOTIV_CUSTOMER_EAN');
// transfer actual field event to server
params["value"] = this.getValue(); // value of EAN_SCAN field
params["soll"] = ctrlSOLL.getValue(); // SAP value

function OnServer()

$prettyprint = preg_replace('/\D/', '',$params["soll"]); // remove all that is not a number
if ($prettyprint == $params["value"]) // compare with value set in Step1
{
$result["ok"] = "on";
}
else
{
$result["ok"] = "";
}

function OnAfter()

var ctrlCB = ctrl.getPeer('EANCode');
if ( result['ok'] == 'on' ) // server side validation said OK
{
ctrlCB.setValue('on'); // this checks the checkbox
ctrl.addStyle('background: yellowgreen'); // this signals to user that validation was OK
}
else
{
ctrlCB.setValue('');
ctrl.addStyle('background: white');
}
admin 5/13/2022

Since we do not have access to your barcode scanner, is there a way to reproduce this issue in a regular web application? It will be easier to provide a meaningful feedback if there is something that we can see in a live app.

C
ckranich authorDevClub member 5/14/2022

Dear Admin,

Thank you for answer!

  1. I am looking after a way to provide a testapp....


  2. Further investigations using Chrome yielded the following facts



  • Any JS keydown/keyup function in the OnLoad js code of the page catches every character
    -The Field Event does only catch MANUAL keys. The barcode scanner's input is ignored completely!
    (maybee the AJAX js-php-js turn around time is too slow?)
  • However the characters scanned in fill the input field, but they are not validated by the Field Event(Edit) code.

  1. I can either detect CR/ENTER in the keydown or by a timeout.
    is there any way to trigger a validation?

My last path to a work around:

  • I setup the validation for the OnClick event of the field Events
  • I can issue a click on the textfield to (re)run validation
    - MISSING: How can I Click on PHPrunner Control from within JS code?

Kind greetings,

ckranich

C
ckranich authorDevClub member 5/14/2022

SOLVED:

How I did this:

  1. Trigger a Timer in Form OnLoad JS

    $(document).keyup(function(e) { // THIS IS TRIGGERED OK
    if (e.keyCode == 13)
    {
    // this is triggered, so CR is seen OK
    setTimeout(function(){
    var bcfield = document.getElementById('value_EAN_SCAN_60026'); // This wants the HTML Id, seen with FF <Q> command
    bcfield.click();
    }, 1000);
    }
    });

    Attention: getElementById demands the HTML Id, not the Id inside PHPrunner; use Firefox <Q> command to get it


  2. Created a Field Event (Click), which does the validation
    (The FieldEvent(Edit) stays active too for manual entry.



Kind Greetings,

ckranich