Wizard

This component can be found under the Sybrin.Document namespace and is called WizardComponent.

Full name: Sybrin.Document.WizardComponent.

It is a component that wraps and orchestrates the rest of the document capture components.

As the user interacts with components housed within the wizard component, it will automatically progress and keep track of steps.

Initialization

The wizard component can be initialized using the following code:

<div id='wizard'></div>

The Sybrin Web SDK provides the option to either provide the ID of the element you wish to use for component initialization, or to provide the element directly.

Please note that 'wizard' is just an example in this context and the ID may be changed as desired as long as it matches the value provided during component initialization in JavaScript.

During initialization, the wizard component allows for a number of configuration options that may be provided using an object literal. The parameters that may be used on the object include the following:

Required:

  • id (string): ID of the element you wish to use for component initialization. Not required if element is provided.

  • element (HTMLElement): Element you wish to use for component initialization. Not required if id is provided.

  • api (Sybrin.Document.Api): Instance of a JavaScript API that may be pre-configured as desired. Not required if an instance of options is passed.

  • options (Sybrin.Document.Options): Configuration options to instantiate Sybrin.Document.Api with. Not required if an instance of api is passed.

Optional:

  • cameraDirectionPriority (number): This property is used to determine which camera direction the SDK should try to prioritize. 0 is none, meaning it will always prompt device selection. 1 is front, meaning it will default to the front camera if only one front device is found. 2 is back, meaning it will default to the rear camera if only one rear device is found.

  • cropSelectionStart (Sybrin.Document.CropSelectionStart): Sets how the crop selection area should be initialized. The options are middle (0) and full (1). The middle option sets the crop selection area to start as a smaller block in the center of the image. The full option will initially select the entire image.

  • steps (string): A collection of strings to specify/override the steps that the wizard should display, as well as their order. The string values may be:

    • 'prepare' to specify the prepare component.

    • 'device-select' to specify the device select component.

    • 'document-capture' to specify the document capture component.

    • 'document-crop' to specify the document crop component.

    • 'result' to specify the result component.

  • readonlyMode (boolean): Disables all events if true. Default false.

  • translations ({ [key: string]: string }): An object literal representing a dictionary lookup that will be used for translating the component. Please see the translations section on this page for a list of all translatable text, as well as the localization page for a detailed description on how to implement localization.

Warning: Initialization will fail if the intended host element does not exist yet.

Always ensure that the initialize function is only called after the DOM is loaded.

Destruction

The wizard component may be removed from the UI by calling the destroy() function on it.

Example:

component.destroy();

Functions

Initialize

initialize(): Promise<void>

Initializes the component's DOM and events. The initialization function is asynchronous.

Destroy

destroy(): void

Destroys the component's DOM and events.

Set Translations

setTranslations(translations?: { [key: string]: string; }): void

Changes the component's translations to the provided values and updates the DOM accordingly.

Get Current Step

getCurrentStep(): StepType

Gets the step that is currently active in the wizard. StepType is:

"prepare" | "device-select" | "document-capture" | "document-crop" | "result";

Back

back(): void

Signals to the wizard to revert to the previous step.

Next

next(): void

Signals to the wizard to proceed to the next step.

Events

The wizard component offers multiple events. To hook onto an event, simply assign a function to it.

The following options are available:

  • onWizardDone(result: DocumentScanResult)

  • onBeforeStepChanged(oldStep: string, newStep: string)

  • onAfterStepChanged(oldStep: string, newStep: string)

  • onCaptureResult(result: DocumentScanResult)

  • onCaptureError(error: string)

  • onCaptureCancelled()

  • onBeforeCapture()

  • onBeforeUpload()

  • onViewPrivacyPolicy()

On Wizard Done

This function is called when all wizard steps have been completed and a result was acquired without error. To hook onto the event, you may use the following code:

component.onWizardDone = function(result) {
    console.log(result);
}

The result parameter is of type Sybrin.Document.DocumentCaptureResult and includes the following properties:

  • success (boolean): Whether or not the document was captured successfully.

  • facingMode (string): The facing direction of the camera used during capture.

  • message (string): Additional information when applicable, for instance an error message if one occurred.

  • originalDocumentImage (string): Base64 string of the original photo of the document.

  • croppedDocumentImage (string): Base64 string of the cropped photo of the document (if the document crop component was used).

  • processedDocumentImage (string): Base64 string of the cropped document image after post-processing was applied. This field is populated by the Result component.

On Before Step Changed

This function is called before the wizard changes to another step. This includes progressing forward or going back to a previous step. To hook onto the event, you may use the following code:

component.onBeforeStepChanged = function(oldStep, newStep) {
    console.log('The old step is: ', oldStep);
    console.log('The new step will be: ', newStep);
}

The oldStep parameter is of type string.

The newStep parameter is of type string.

On After Step Changed

This function is called after the wizard changed to another step. This includes progressing forward or going back to a previous step. To hook onto the event, you may use the following code:

component.onAfterStepChanged = function(oldStep, newStep) {
    console.log('The old step was: ', oldStep);
    console.log('The new step is: ', newStep);
}

The oldStep parameter is of type string.

The newStep parameter is of type string.

On Capture Result

This event bubbles the onCaptureResult event up once it executes on the document capture component.

On Capture Error

This event bubbles the onCaptureError event up once it executes on the document capture component.

On Capture Cancelled

This event bubbles the onCaptureCancelled event up once it executes on the document capture component.

On Before Capture

This event bubbles the onBeforeCapture event up once it executes on the document capture component.

On Before Upload

This event bubbles the onBeforeUpload event up once it executes on the prepare component.

On View Privacy Policy

This event bubbles the onViewPrivacyPolicy event up once it executes on the prepare component.

Styling

The wizard component is structured a follows:

<div class="sybrin-document-wizard sybrin-sdk-wizard">
    <div class="sybrin-document-wizard-viewport sybrin-sdk-wizard-viewport">
    </div>
</div>

Since the wizard component has no visual elements by itself, no styling is necessary. Please style individual components housed within the wizard instead.

Translations

The translations provided to this component are in turn provided to the internal components hosted by it. Please see individual component translation sections for details on which translation keys are available to them, and also the localization section for an overview on available keys and how to make use of localization functionality.

Last updated