Prepare
The prepare component can be found under the Sybrin.Document
namespace and is called PrepareComponent
.
Full name: Sybrin.Document.PrepareComponent
.
It provides an interface for selecting a desired capture method, as well as an easy way to view a customizable privacy policy and usage guidelines.
With default styling, the prepare component appears as follows:
Upon clicking "View Our Privacy Policy", the onViewPrivacyPolicy
event will fire. Hooking onto this event allows you to react to the button click and show your privacy policy.
Clicking "Upload Photo" will fire the onBeforeUpload
event and then invoke the uploadDocument
function of the JavaScript API, resulting in a file picker popping up and allowing the user to complete data extraction using a file upload. Completion will result in the onCaptureResult
event firing, and an error will result in the onCaptureError
event firing. Cancelling will fire the onCaptureCancelled
event. If a multi-sided document type is selected, a specialized multi file selection window will be presented:
Clicking "Take Photo" will result in the onTakePhoto
event firing, which can then be used as a signal to initialize the document capture component, or the device select component first should the user system possess multiple viable video input devices.
Initialization
The prepare component can be initialized using the following code:
The countryCode parameter may be obtained using the Country Select component.
The documentTypeId and documentTypeName parameters may be obtained using the Document Select component.
The Sybrin Web SDK provides the option to either pass down the ID of the element you wish to use for component initialization, or to pass the element directly.
Please note that 'prepare' is just an example in this context and the ID may be changed as desired as long as it matches the value passed down during component initialization in JavaScript.
During initialization, the prepare 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 ifelement
is passed.element (HTMLElement)
: Element you wish to use for component initialization. Not required ifid
is passed.api (Sybrin.Document.Api)
: Instance of a JavaScript API that may be pre-configured as desired. Not required if an instance ofoptions
is passed. This is the instance that will be used for invoking photo upload functionality.countryCode
: The country code of the document. Used during uploads, in conjunction with document type parameters, to determine page count. May be obtained by using the Country Select component.documentTypeName
: The document type name of the document. Used during uploads, in conjunction with country code parameters, to determine page count. May be obtained by using the Document Select component.documentTypeId
: The document type ID of the document. Used during uploads, in conjunction with country code parameters, to determine page count. May be obtained by using the Document Select component.options (Sybrin.Document.Options)
: Configuration options to instantiateSybrin.Document.Api
with. Not required if an instance ofapi
is passed. This is the instance that will be used for invoking photo upload functionality.
Optional:
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.imageUploadFormat (string: 'original' | 'jpeg')
: Sets the format that images will be converted to for upload. Defaults to original.
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 prepare component may be removed from the UI by calling the destroy()
function on it.
Example:
Functions
Initialize
initialize(): void
Initializes the component's DOM and events.
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.
Events
The prepare component offers multiple events. To hook onto an event, simply assign a function to it.
The following options are available:
onCaptureResult(result: DocumentCaptureResult)
onCaptureError(error: string)
onCaptureCancelled()
onBeforeUpload()
onTakePhoto()
onViewPrivacyPolicy()
On Capture Result
This function is called after image capture runs without error once the "Upload Photo" button is clicked. To hook onto the event, you may use the following code:
The result parameter is of type Sybrin.Document.DocumentCaptureResult
and includes the following properties:
success (boolean)
: Whether or not image capture executed successfully.message (string)
: Additional information when applicable, for instance an error message if one occurred.facingMode (string):
The camera facing mode used for capture.originalDocumentImage (string)
: Base64 string of the original photo of the document.croppedDocumentImage (string)
: Base64 string of the cropped document image. This field is populated by the Document Crop component.processedDocumentImage (string)
: Base64 string of the cropped document image after post-processing was applied. This field is populated by the Result component.
On Capture Error
This function is called when something goes wrong and an error occurs during image capture. To hook onto the event, you may use the following code:
The error parameter is of type string.
On Capture Cancelled
This function is called when image capture was started, but then cancelled before completion. To hook onto the event, you may use the following code:
No parameter is provided to this function call.
On Before Upload
This function is called before the file upload window appears. To hook onto the event, you may use the following code:
No parameter is provided to this function call.
On Take Photo
This function is invoked when the "Take Photo" button is clicked. To hook onto the event, you may use the following code:
No parameter is provided to this function call.
On View Privacy Policy
This function is invoked when the "View Our Privacy Policy" button is clicked. To hook onto the event, you may use the following code:
No parameter is provided to this function call.
Styling
The prepare component is structured a follows:
The classes and elements specified above may be used to freely style the prepare component as desired. To do so, simply create a stylesheet and include it in the project, then style according to the above classes and elements.
Styling implementation example:
Translations
Currently, no translations are available.
Last updated