Hosted Fields JS
Initialize
You can initialize the fields by calling the init()
method. Once this method is called, the sdk will emit the initializing
, initialized
, and/or the init_error
change events.
window.gravityLegal.init(options: Options): Promise<void>;
You can call init()
multiple times in the same context. Each call will trigger a new initializing
, initalized
, and/or init_error
sequence. The fields will also be reloaded each time init()
is called.
Example
Example initializing the hosted fields for a Payment session.
async function initHostedFields() {
const res = await getPaymentTokenFromMyBackend();
const fieldStyles = {
border: 'none',
color: 'rgb(26, 32, 44)',
'font-family':
'-apple-system, "system-ui", "Segoe UI", Helvetica, Arial, sans-serif',
'font-weight': 400,
height: '38px',
width: '100%',
'font-size': '16px',
};
window.gravityLegal.init({
paymentToken: res.paymentToken,
activeForm: 'card',
fields: {
accountNumber: {
containerId: 'account-number',
style: fieldStyle,
},
accountHolderName: {
containerId: 'account-holder-name',
style: fieldStyle,
},
routingNumber: {
containerId: 'routing-number',
style: fieldStyle,
},
cardNumber: {
containerId: 'card-number',
style: fieldStyle,
},
cardExpirationDate: {
containerId: 'card-exp',
style: fieldStyle,
},
cardSecurityCode: {
containerId: 'card-cvv',
style: fieldStyle,
},
}
});
}
Method parameters
Details for each property on the options object.
Initialization options.
Hide Properties
- paymentTokenstring
Payment Token returned from a Start Payment Session call. Required when using a Payment Session type.
- savePaymentMethodTokenstring
Token returned from a createSavePaymentMethodToken mutation call. Required when using a Save Payment Method Session type.
- activeFormenumrequired
Form type to initialize first. The div's for the respected fields must be in the DOM before you initialize. The SDK uses document.getElementById(containerId) to find the element.
Show Enum Values
- fieldsobject (FieldConfigMap)required
Configuration for the hosted fields
Open Properties