To provide a great UI/UX experience on your page you will want to know when changes happen within the fields. You can add any number of change listeners to the sdk that will be called when the internal state of the fields change.

const myListener = (e: ChangeEvent) => {
  console.log(e);
};

window.gravityLegal.addChangeListener(myListener);

// then later, clean it up
window.gravityLegal.removeChangeListener(myListener);

Event Types

TypeDescription
bin_changeEmitted when the first 6 digits of the card number field changes
bin_loadedAfter the bin number changes, the sdk makes a network call to get more information about the current card, including the card type (debit or credit). This event is emitted after this network call returns.
field_error_clearedEmitted when a field, that was previously in error, is fixed.
fields_loadedEmitted when all the fields of the active form type are finished loading.
initializingEmitted immediately following a call tosdk.init()
initializedEmitted once initialization is done and successful.
init_errorEmitted when there’s an error with initialization.

ChangeEvent Fields

type
string
required

The type of event. This can be one of the types listed above.

state
object
required

The current state of the fields. See the State Object for more details.