Events
ElementEvent
iOS Element events are triggered whenever a user types into an element text field. An ElementEvent is the struct that gets passed into the subject’s receiveValue function. The following are properties on the ElementEvent struct:
| Property | Description | 
|---|---|
| type | The event type for the ElementEvent. | 
| complete | Whether the input validandmaskSatisfiedproperties aretrue. | 
| valid | Whether the input is validaccording tovalidationfor each element. | 
| maskSatisfied | Whether the input satisfies the masklength requirements. | 
| details | An array of ElementEventDetail describing more information about the element event. | 
ElementEvent Types
The following are the available element event types and their descriptions.
| Type | Description | 
|---|---|
| textChange | All elements emit this event when a user changes an element's value. | 
| focus | All elements emit this event on textFieldDidBeginEditing. | 
| blur | All elements emit this event on textFieldDidEndEditing. | 
| maskChange | CardVerificationCodeUITextFieldelements emit this event when its mask has changed. | 
ElementEventDetail
| Property | Description | 
|---|---|
| type | A Stringdescribing the type of detail. | 
| message | A Stringcontaining the message for the detail. | 
ElementEventDetail Types
The following are the available element event detail types and their descriptions.
| Type | Description | 
|---|---|
| cardBrand | CardNumberUITextFieldelements emit a card brand name when a card number can be identified. | 
| cardLast4 | CardNumberUITextFieldelements emit the last 4 digits of a card number when the input is consideredcomplete. | 
| cardBin | CardNumberUITextFieldelements emit the first 6 or 8 digits of a card number when the input is consideredcomplete. It is 6 digits for card numbers less than 16 digits long and 8 otherwise. | 
Usage
You can observe element events through the PassThroughSubject subject field on every element.
private var cancellables = Set<AnyCancellable>()
...
myTextField.subject.sink { completion in
    ...
} receiveValue: { elementEvent in
    ...
}.store(in: &cancellables)
Using Metadata for Event Values
Instead of subscribing to events, the same properties can be accessed at any time from the metadata property on all elements.
Additionally, the card related event details can be accessed from the cardMetadata property only on CardNumberUITextField.
The following are the available properties accessible from metadata.
| Property | Type | Description | 
|---|---|---|
| complete | Bool | Whether the input validandmaskSatisfiedproperties aretrue. | 
| valid | Bool | Whether the input is validaccording tovalidationfor each element. | 
| maskSatisfied | Bool | Whether the input satisfies the masklength requirements. | 
The following are the available properties accessible from cardMetadata.
| Property | Type | Description | 
|---|---|---|
| cardBrand | String | Card brand name when a card number can be identified. | 
| cardLast4 | String | Last 4 digits of a card number when the input is considered complete. | 
| cardBin | String | First 6 or 8 digits of a card number when the input is considered complete. It is 6 digits for card numbers less than 16 digits long and 8 otherwise. |