Country Select

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

Full name: Sybrin.Document.CountrySelectComponent.

It is a component that provides basic country selection functionality in the form of a simple UI. The Web SDK requires a country code for capture and OCR, and it's recommended that you use this component to obtain said country code.

With default styling, the country select component appears as follows:

The "Next" button will remain disabled until a country has been selected. Selection is confirmed upon clicking the "Next" button and then the onCountrySelected event will fire.

Initialization

The country select component can be initialized using the following code:

<div id='country-select'></div>

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 'country-select' 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 country select component allows for a number of configuration options that may be passed down 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 passed.

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

Optional:

  • defaultCountry (string): The country code of the country that must be selected by default.

  • documentTypeName (string): The document type name to filter country selection by. If a document type name is passed down, only countries that support the specified document type will be shown. Please see document type overrides & filtering for a list of accepted values.

  • countries (Sybrin.Document.Country[]): Explicit country filter. Please see country overrides & filtering for details.

  • 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.

Country Overrides & Filtering

When creating an instance of the country select component, the SDK allows for a documentTypeNamestring parameter, which will be used to filter countries based on the document type. Additionally, the SDK allows for a countries parameter which can be used for more specific override options. The countries parameter is a collection of Sybrin.Identity.Country where each instance has the properties code, name and enabled.

  • code (string): The unique identifier (Alpha-3 standard country code) used to target a country to override.

  • name (string): Can be used to override the display name of the targeted country.

  • enabled (boolean): Can be used to filter out the targeted country (if set to false)

Supported country codes are:

  • Kenya: 'KEN'

  • Other: 'GEN'

Advanced filtering and override example:

var component = new Sybrin.Document.CountrySelectComponent({
    id: 'viewport',
    documentTypeName: 'birthcertificate',
    countries: [
        new Sybrin.Document.Country({ code: 'GEN', name: 'Any Other Country' }),
        new Sybrin.Document.Country({ code: 'KEN', enabled: false })
    ]
});

By specifying documentTypeName as 'birthcertificate', it will only show countries that support the birth certificate document type. The first country instance in the countries collection overrides 'GEN', which is the generic option, to display as "Any Other Country" instead. The second instance filters 'KEN', which is Kenya, out so that it doesn't appear as part of the list even though the Kenyan birth certificate document type is supported.

Destruction

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

Example:

component.destroy();

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 country select component offers one event for reacting to country selection. To hook onto the event, simply assign a function to it.

The following option is available:

  • onCountrySelected(alpha3Code: string, alpha2Code: string, numericCode: string)

On Country Selected

This function is called when a country is selected. To hook onto the event, you may use the following code:

component.onCountrySelected = function(alpha3Code, alpha2Code, numericCode) {
    console.log('The selected country Alpha-3 code is: ', alpha3Code);
    console.log('The selected country Alpha-2 code is: ', alpha2Code);
    console.log('The selected country numeric code is: ', numericCode);
}

The alpha3Code, alpha2Code and numericCode parameters are all of type string.

Styling

The country select component is structured a follows:

<div class="sybrin-document-container sybrin-sdk-container sybrin-document-country-select">
    <div class="sybrin-document-component-section sybrin-sdk-component-section">
        <div class="sybrin-document-list sybrin-sdk-list sybrin-custom-scrollbar">
            <div class="sybrin-document-card sybrin-sdk-card sybrin-country-KEN">
                <div class="sybrin-document-card-image">
                    <img src="data:image/png;charset=utf-8;base64,">
                </div>
                <div class="sybrin-document-text">
                    Kenya
                </div>
            </div>
        </div>
    </div>
    <div class="sybrin-document-button-section sybrin-sdk-button-section">
        <button disabled="disabled" class="sybrin-document-next sybrin-document-flow-button sybrin-sdk-flow-button">
            Next
        </button>
    </div>
</div>

The classes and elements specified above may be used to freely style the country select 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.

The element with the sybrin-document-card class repeats for every country option. The above example only uses Kenya as an example, however the same element would repeat for each country option in the list, using the relevant country code for the CSS class and the relevant country name in the display text.

Styling implementation example:

index.html
<html>
<head>
    <link rel="stylesheet" type="text/css" href="styles.css" media="screen"/>
</head>
<body>
    <div id='component'></div>
</body>
</html>

Translations

Currently, no translations are available.