Skip to main content

Overview

Elements is the set of secure card fields for one payment. You create it from your publishable key, scoped to a single intent by its client_secret, so every field you render belongs to that one intent.

Create and mount fields

create instantiates one field as a secure Modulus iframe. mount inserts that iframe into a placeholder element on your page, by CSS selector or DOM node. The customer types into the iframe, and your page cannot read its contents.
Use split fields (number / expiry / cvc) or a single combined 'card' field.
Choose one model. Do not mix a split cardNumber field with the combined card field in the same form.

Field types

create() options

style properties

Appearance

Style every field in the group at once with an appearance.variables object passed to elements(). Per-field style overrides (above) layer on top of these.

Element methods

Group methods

The Elements group exposes methods for driving your form and cleanup:

Field events

Subscribe per field with element.on(...), or once on the whole group with elements.on('change'). The group listener is the easy way to drive your Pay button.
The group change fires on every keystroke in any field. Its complete is true only when every mounted field is valid and filled, so gating on it keeps Pay disabled until the whole card form is ready, then enables it.
A field fires loaderror when its secure iframe cannot come up, for example the customer’s network dropped mid-load, an ad-blocker or corporate proxy blocked the Modulus domain, or the secure-channel handshake timed out after the SDK’s own retries. Surface a reload affordance and call element.retry().