eLabSDK.Barcode

Functions

NameDescription
testScan(val)Simulate a barcode scan for testing purposes.

This triggers the barcode scan callback with a test value, allowing you to test barcode
functionality without a physical barcode scanner. The scan will only execute if the
scanner is currently enabled. Use this during development and testing to verify your
barcode handling logic works correctly.
disable() | Disable barcode scanning temporarily.

This prevents the barcode scanner from processing any scanned barcodes or keyboard input.
The scanner will ignore all barcode events until it is re-enabled. Use this when you need
to temporarily pause barcode scanning, such as during form input, dialog interactions, or
when switching between different scanning modes.
enable() | Enable barcode scanning after it was disabled.

This re-enables the barcode scanner to process scanned barcodes and keyboard input.
The scanner will resume processing barcode events normally. Use this to resume barcode
scanning after temporarily disabling it, such as after closing a dialog or completing
form input.
overrideBulkBarcodeAction(cfg) | Override the default bulk barcode scanner save action with custom processing logic.

This allows you to intercept and customize the bulk barcode scanning workflow before
samples are updated. You can add custom validation, modify the data being saved, or
prevent the default save action entirely. The callback receives a data object that can
be modified to control the processing flow. For asynchronous operations, set
continueProcess to false and call data.finalize() manually when ready.
initScan(callback) | Initialize barcode scanning by listening for rapid keyboard input from a barcode scanner.

This sets up a keyboard event listener that detects rapid key presses characteristic of
barcode scanners (characters entered within 250ms of each other). When a complete barcode
is detected (no more characters for 500ms), the provided callback is executed with the
scanned barcode value. The scanner automatically filters out control characters and
handles special characters like @ and -. Use this to enable barcode scanning functionality
on any page where users might scan barcodes.

testScan(val)

Simulate a barcode scan for testing purposes.

This triggers the barcode scan callback with a test value, allowing you to test barcode
functionality without a physical barcode scanner. The scan will only execute if the
scanner is currently enabled. Use this during development and testing to verify your
barcode handling logic works correctly.

Kind: global function

ParamTypeDescription
valstringThe test barcode value to simulate scanning

Example

// Create barcode scanner and test it
var scanner = new eLabSDK.Barcode();
scanner.initScan(function(barcode) {
  console.log('Scanned: ' + barcode);
});

// Simulate scanning a barcode
scanner.testScan('TEST-12345');

Example

// Test different barcode formats
var scanner = new eLabSDK.Barcode();
scanner.initScan(function(barcode) {
  alert('Barcode: ' + barcode);
});

scanner.testScan('SAMPLE-001'); // Test alphanumeric
scanner.testScan('123456789');  // Test numeric

disable()

Disable barcode scanning temporarily.

This prevents the barcode scanner from processing any scanned barcodes or keyboard input.
The scanner will ignore all barcode events until it is re-enabled. Use this when you need
to temporarily pause barcode scanning, such as during form input, dialog interactions, or
when switching between different scanning modes.

Kind: global function
Example

// Disable scanner during dialog input
var scanner = new eLabSDK.Barcode();
scanner.initScan(function(barcode) {
  console.log('Scanned: ' + barcode);
});

// Show dialog and disable scanner
var dialog = new eLabSDK.GUI.Dialog({
  title: 'Enter Data',
  content: '<input type="text" id="userInput" />'
});
scanner.disable(); // Prevent barcode interference during typing
dialog.render();

Example

// Disable/enable based on UI state
var scanner = new eLabSDK.Barcode();
scanner.initScan(handleBarcode);

$('#editMode').on('click', function() {
  scanner.disable();
  console.log('Barcode scanning disabled during edit mode');
});

enable()

Enable barcode scanning after it was disabled.

This re-enables the barcode scanner to process scanned barcodes and keyboard input.
The scanner will resume processing barcode events normally. Use this to resume barcode
scanning after temporarily disabling it, such as after closing a dialog or completing
form input.

Kind: global function
Example

// Re-enable scanner after dialog closes
var scanner = new eLabSDK.Barcode();
scanner.initScan(function(barcode) {
  console.log('Scanned: ' + barcode);
});

// Disable during dialog
scanner.disable();
var dialog = new eLabSDK.GUI.Dialog({
  title: 'Enter Data',
  content: '<input type="text" />'
});
dialog.render();

// Re-enable when dialog closes
$('#closeDialog').on('click', function() {
  dialog.close();
  scanner.enable();
});

Example

// Toggle scanner based on checkbox
var scanner = new eLabSDK.Barcode();
scanner.initScan(handleBarcode);

$('#enableScannerCheckbox').on('change', function() {
  if (this.checked) {
    scanner.enable();
    console.log('Scanner enabled');
  } else {
    scanner.disable();
    console.log('Scanner disabled');
  }
});

overrideBulkBarcodeAction(cfg)

Override the default bulk barcode scanner save action with custom processing logic.

This allows you to intercept and customize the bulk barcode scanning workflow before
samples are updated. You can add custom validation, modify the data being saved, or
prevent the default save action entirely. The callback receives a data object that can
be modified to control the processing flow. For asynchronous operations, set
continueProcess to false and call data.finalize() manually when ready.

Kind: global function

ParamTypeDescription
cfgobjectConfiguration object for the override
cfg.uniqueIDstringRequired unique identifier to ensure subscription only happens once (prevents duplicate handlers)
cfg.callBackFnfunctionFunction to call for custom processing. Receives data object as parameter
cfg.callBackFn.dataobjectData object passed to callback, can be modified to control processing
cfg.callBackFn.data.continueProcessbooleanSet to true to continue default processing, false to prevent it
cfg.callBackFn.data.errorMessagestringOptional custom error message to display if continueProcess is false
cfg.callBackFn.data.finalizefunctionFor async operations, call this manually after setting continueProcess to false

Example

// Add custom validation before bulk barcode save
var barcode = new eLabSDK.Barcode();
barcode.overrideBulkBarcodeAction({
  uniqueID: 'myCustomValidation',
  callBackFn: function(data) {
    // Validate scanned barcodes
    var isValid = validateBarcodeData(data);
    if (!isValid) {
      data.continueProcess = false;
      data.errorMessage = 'Invalid barcode format detected';
    } else {
      data.continueProcess = true;
    }
  }
});

Example

// Async processing with finalize
var barcode = new eLabSDK.Barcode();
barcode.overrideBulkBarcodeAction({
  uniqueID: 'asyncBarcodeProcess',
  callBackFn: function(data) {
    // Prevent default processing
    data.continueProcess = false;
    
    // Perform async operation
    $.post('/api/validate-barcodes', data, function(response) {
      if (response.valid) {
        // Continue with save
        data.continueProcess = true;
        data.finalize();
      } else {
        data.errorMessage = 'Validation failed: ' + response.error;
        data.finalize();
      }
    });
  }
});

initScan(callback)

Initialize barcode scanning by listening for rapid keyboard input from a barcode scanner.

This sets up a keyboard event listener that detects rapid key presses characteristic of
barcode scanners (characters entered within 250ms of each other). When a complete barcode
is detected (no more characters for 500ms), the provided callback is executed with the
scanned barcode value. The scanner automatically filters out control characters and
handles special characters like @ and -. Use this to enable barcode scanning functionality
on any page where users might scan barcodes.

Kind: global function

ParamTypeDescription
callbackfunctionFunction called when a barcode is successfully scanned. Receives the barcode string as parameter.

Example

// Basic barcode scanning setup
var scanner = new eLabSDK.Barcode();
scanner.initScan(function(barcode) {
  console.log('Scanned barcode: ' + barcode);
  alert('Barcode: ' + barcode);
});

Example

// Look up sample by scanned barcode
var scanner = new eLabSDK.Barcode();
scanner.initScan(function(barcode) {
  console.log('Looking up sample: ' + barcode);
  
  $.get('/api/v1/samples', { barcode: barcode }, function(sample) {
    if (sample) {
      displaySampleDetails(sample);
    } else {
      alert('Sample not found: ' + barcode);
    }
  });
});

Example

// Scan barcodes into a list
var scanner = new eLabSDK.Barcode();
var scannedBarcodes = [];

scanner.initScan(function(barcode) {
  scannedBarcodes.push(barcode);
  $('#barcodeList').append('<li>' + barcode + '</li>');
  console.log('Total scanned: ' + scannedBarcodes.length);
});

Example

// Enable/disable scanner based on context
var scanner = new eLabSDK.Barcode();
scanner.initScan(function(barcode) {
  if (scanner.enabled) {
    processScan(barcode);
  }
});

// Disable when modal is open
$('#myModal').on('show', function() {
  scanner.disable();
}).on('hide', function() {
  scanner.enable();
});

© 2023 eLabNext