Reference Documentation

CanopyConnectComponents

.form(options)

Returns a Form

Creates a FormComponent instance for a specific carrier.

Kind: static method of CanopyConnectComponents

ParamTypeDescription
optionsObjectForm options
options.carrierConfigObjectOne of the configs returned by GET /carriers for which you would like to create a authentication form for.
[options.fonts]ArrayArray of font face objects that are either a Font Face Object or a Font CSS Object.
[options.styles]ObjectGlobal styles that will be used across all input types. The structure is defined here and lists the available states, styles and pseudo-selectors.
[options.usernameStyles]ObjectStyles that will be applied to the username input. Will override the global styles. The structure is defined here and lists the available states, styles and pseudo-selectors.
[options.passwordStyles]ObjectStyles that will be applied to the password input. Will override the global styles. The structure is defined here and lists the available states, styles and pseudo-selectors.
[options.thirdfieldStyles]ObjectStyles that will be applied to the thirdfield input. Will override the global styles. The structure is defined here and lists the available states, styles and pseudo-selectors.
[options.onTokensAvailable]CallbackTriggered when tokens are available after form.submit() is called. Reference .on('tokensavailable') for callback data shape.
[options.onError]CallbackTriggered when there is an error loading/submitting form fields. Reference .on('error') for callback data shape.
[options.onDestroy]CallbackTriggered when the form is destroyed after form.destroy() is called.

Form

.destroy()

Destroys and deletes every component and will trigger the destroy event.

Kind: instance method of Form

.on('change', callback)

Triggered when an input in the form is changed. Callback contains validation information.

Kind: instance method of Form

ParamTypeDescription
dataObjectEvent data.
data.typestringThe input type. Possible values: username, password, thirdfield.
data.emptyBooleanWhether the input is empty.
data.completeBooleanWhether the input passes validation and is ready to be submitted.
[data.error]StringThe error string, exists if input is empty or does not pass validation.

.on('destroy', callback)

Triggered after the form and it's components are destroyed, after .destroy() is called.

Kind: instance method of Form

.on('error', callback)

Triggered when there is an error loading/submitting form fields.

Kind: instance method of Form

ParamTypeDescription
dataobjectEvent data.
data.errstringThe error message.

.on('ready', callback)

Triggered when the form and it's fields are loaded and ready.

Kind: instance method of Form

.on('submit', callback)

Triggered when the enter key/return is pressed.

Kind: instance method of FieldComponent

.on('tokensavailable', callback)

Triggered when tokens are available after .submit() is called.

Kind: instance method of Form

ParamTypeDescription
dataobjectEvent data.
data.usernamestringInput tokenized value.
[data.password]stringInput tokenized value.
[data.thirdfield]stringInput tokenized value.

.ready()

Returns a Promise that gets resolved when all of the components are mounted and ready.

Kind: instance method of Form

.submit()

Returns a Promise<{ errors?: Object; tokens?: Object; }>

Submits the input for all of the components and returns the tokenized value for each input.

Will contain errors if any input fails validation:

{ errors: { [username|password|thirdfield]: { error: string, isEmpty: boolean } } }

Will contain tokens if all inputs pass validation:

{ tokens: { username: string, [password]: string, [thirdfield]: string } }

Kind: instance method of Form

.components: object

A object containing all of the available components based on the provided carrierConfig

Kind: instance property of Form

ParamTypeDescription
usernameFieldComponentUsername authentication field
[password]FieldComponentPassword authentication field. Exists if the carrierConfig has disablePasswordField set to false.
[thirdfield]FieldComponentThird authentication field. Exists if the carrierConfig has thirdFieldPlaceholder.

FieldComponent

.blur()

Calls blur on the field's input.

Kind: instance method of FieldComponent

.destroy()

Unmounts and removes the field and will trigger the destroy event.

Kind: instance method of FieldComponent

.focus()

Calls focus on the field's input.

Kind: instance method of FieldComponent

.on('blur', callback)

Triggered when the input loses focus and becomes blurred

Kind: instance method of FieldComponent

.on('change', callback)

Triggered when the input field is changed. Callback includes validation information.

Kind: instance method of FieldComponent

ParamTypeDescription
dataObjectEvent data.
data.emptyBooleanWhether the input is empty.
data.completeBooleanWhether the input passes validation and can be submitted.
[data.error]StringThe error string, exists if input is empty or does not pass validation.

.on('destroy', callback)

Triggered after .destroy() is called and the field was unmounted.

Kind: instance method of FieldComponent

.on('error', callback)

Triggered when there is an error loading/submitting.

Kind: instance method of FieldComponent

ParamTypeDescription
dataobjectEvent data.
data.errstringThe error message.

.on('focus', callback)

Triggered when the input gains focus

Kind: instance method of FieldComponent

.on('ready', callback)

Triggered after being mounted and the field finishes loading.

Kind: instance method of FieldComponent

.on('tokenavailable', callback)

Triggered when the a token is available after .submit() is called

Kind: instance method of FieldComponent

ParamTypeDescription
dataObjectEvent data.
data.tokenStringInput tokenized value.

.mount(selectorOrElement)

Mounts the FieldComponent to the matching selector or the element.

Kind: instance method of FieldComponent

ParamTypeDescription
selectorOrElementString | HTMLElementThe selector or element that the FieldComponent should be mounted to.

.unmount()

Unmounts the FieldComponent from the currently mounted element.

Kind: instance method of FieldComponent

.validate()

Returns a Promise<Object> - { type: "username|password|thirdfield", isValid: boolean, isEmpty: boolean, error?: string }

Validates the input's value, should be used before calling .submit().

Kind: instance method of FieldComponent