HomeGuidesReference
Log In
Reference

on()

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

TypeDescription
elementEvent

required

EBT Element eventThe EBT Element event that calls the handler.
handler

required

functionA 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

balanceElement.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('')
  }
})