Skip to main content
Primer Checkout iOS SDK is currently in beta (v3.0.0-beta.1). The API is subject to change before the stable release.
The card form validates each field and surfaces the results through PrimerCardFormState. Read validation state from the PrimerCardFormSession inside your custom slots to display targeted error messages and gate submission.

FieldError

A FieldError represents a validation error for a single form field. It is Equatable and Identifiable (its id is the fieldType), so it works directly with SwiftUI’s ForEach.

Validation surfaces on PrimerCardFormState

Validation is exposed through the form state held by PrimerCardFormSession. Observe the session with @ObservedObject (or @StateObject) and read session.state.
isValid reflects the form’s overall validity and updates as the user edits fields. Use it to drive the enabled state of your submit button, and use fieldErrors / errorMessage(for:) to render per-field messages.

Reading a field error inside a slot

Use the helpers on session.state to show an inline error for a specific field. The example below renders a CVV field that highlights its border and shows a message when validation fails.
To enumerate every error currently present in the form, iterate fieldErrors directly — FieldError is Identifiable, so it slots into ForEach.

Gating submission with isValid

Bind your submit button’s enabled state to session.state.isValid so it activates only once the form passes validation.

PrimerInputElementType

PrimerInputElementType identifies the type of input field referenced by a FieldError (and used throughout the card form). Each case has a stringValue returning the canonical string identifier.
You typically don’t construct FieldError yourself — the SDK populates fieldErrors for you. Read it through session.state and use hasError(for:) / errorMessage(for:) to drive your UI.

See also

Card form session

The observable session that exposes form state, mutation methods, and submission.

Card field components

Built-in field views you can compose inside the card form slots.