element.on(elementEvent, handler)
Adds an event handler to the EBT Element
for the provided event. When the event fires, the handler is called.
Parameters
Type | Description | |
---|---|---|
elementEvent required | EBT Element event | The EBT Element event that calls the handler. |
handler required | function | A callback that fires when the provided event occurs. |
Examples
In these examples, the ForagePinElement
is used for a balance check.
Listen for input changes on a ForagePinElement
and display a message if there’s a validation error
ForagePinElement
and display a message if there’s a validation errorbalanceElement.on('change', (event) => {
const explainErrorSpan = document.getElementById('explain-error')
if (event.error) {
// show validation error to customer
explainErrorSpan.textContent = event.error.message
} else {
// hide validation error
explainErrorSpan.textContent = ''
}
})
(React-oriented) Listen for input changes and display a message if there’s a validation error
balanceElement.on('change', (event) => {
if (event.error) {
// show validation error to customer
setValidationMessage(event.error.message)
} else {
// hide validation error
setValidationMessage('')
}
})