I am using bar code scanner in SAP UI5. In case the camera doesn’t open up or if the scan fails, the bar code scanner shows an Input box. I want to disable that. How can I do that?

by | Apr 20, 2023 | UI5 Bugs

Case 1: XML

To disable the input box in the barcode scanner in SAP UI5, you can set the property showInputBar of the barcode scanner control to false. This will hide the input box and prevent it from being displayed even if the camera fails to open or the scan fails.

Here’s an example code snippet showing how to disable the input box in a SAP UI5 barcode scanner control:

var oScanner = new sap.ndc.BarcodeScanner();
oScanner.showInputBar = false;

You can also set the showInputBar property directly in the XML view definition of the barcode scanner control, like this:

<ndc:BarcodeScanner showInputBar="false" />

By setting the showInputBar property to false, the input box in the barcode scanner will be disabled and hidden from the user interface.

Case 2: Controller

To disable the input box in the barcode scanner in SAP UI5 via the controller using the sap.ndc.BarcodeScanner.scan method, you can modify your code as shown below:
sap.ndc.BarcodeScanner.scan(
  function(oScanData) {
    console.log("Scanning Success: " + oScanData);
    var n = oScanData.text;
    if (n.length > 0) {
      var scannedText = oScanData.text;
    }
  },
  function(e) {
    console.log("Scanning failed: " + e);
  },
  {
    showInputBar: false // Disable the input box in the barcode scanner
  }
);

In the sap.ndc.BarcodeScanner.scan method, we have added an options parameter as the third argument, which is an object containing the options for the barcode scanner. We have set the showInputBar property of the options object to false to disable the input box in the barcode scanner.

By setting the showInputBar property to false, the input box in the barcode scanner will be disabled and hidden from the user interface even if the camera fails to open or the scan fails.

Author

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Advertisement

Advertisement

Advertisement

Advertisement