
valueHelpRequest
as the trigger for the BarcodeScanner.scan
function, we are able to allow for both manual input and ease of access to the scanning feature.<Input
id="barcodeScannerInput"
type="Text"
value="{/BarCode}"
valueHelpRequest="openScannerForInput('barcodeScannerInput', 'barcodeScannerInputCallback')"
valueHelpIconSrc="sap-icon://bar-code"
showValueHelp="true"
/>
openScannerForInput
function takes two arguments, the id of the input which should have it's value replaced with the scanned value, and an optional callback function name./**
* Open Scanner Input is called from inside the View
*/
openScannerForInput(input, callback) {
this._openScannerForInput(this.getView(), input, callback)
}
/**
* Helper function for openScannerInput
* receives an extra parameter for the current view that is calling the function
*/
_openScannerForInput(view, input, callback) {
if (typeof input === 'string') {
input = view.byId(input)
}
// https://sapui5.hana.ondemand.com/#/api/sap.ndc.BarcodeScanner%23methods/sap.ndc.BarcodeScanner.scan
sap.ndc.BarcodeScanner.scan((data) => {
const barcode = data.text
if (barcode) {
sap.m.MessageToast.show(" Barcode Detected " + barcode)
input.setValue(barcode)
if (callback) view.getController()[callback](barcode)
}
}, undefined, undefined, undefined, undefined, undefined, 1, false)
}
barcodeScannerInputCallback(code) {
var oModel = this.getView().getModel();
//handle extra logic for when barcode is scanned for an input here
this.getOwnerComponent().getModel("ODataBackend").read(
// the `code` parameter and the `/BarCode` property on our model will be the same
// `/BarCodeEntitySet('${oModel.getProperty("/BarCode")}')`
`/BarCodeEntitySet('${code}')`,
{
success: (oData, oResponse) => {
.setProperty("/BarCodeEntitySet", oData)
},
error: (oData, oResponse) => {
console.error(error)
}
}
)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
10 | |
9 | |
7 | |
5 | |
5 | |
4 | |
4 | |
3 | |
3 |