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

Listen for input changes on a ForageEbtBalanceElement and display a message if there’s a validation error

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

ebtBalanceCheckElement.on('change', (event) => {
  if (event.error) {
    // show validation error to customer
    setValidationMessage(event.error.message)
  } else {
    // hide validation error
    setValidationMessage('')
  }
})