Skip to main content
Primer Checkout iOS SDK is currently in beta (v3.0.0-beta.8). The API is subject to change before the stable release.
The card form’s built-in field views validate each field and surface the results through PrimerCardFormState. A field shows an error when the shopper leaves it with an invalid value. The CVV field also validates as soon as it reaches its full length. The error clears when the shopper focuses that field again. Empty fields never show an error message. Values you write with the session’s update* methods never produce a FieldError. They count toward isValid only while the matching SDK field view is on screen. Read validation state from the PrimerCardFormSession inside your custom slots to display targeted 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 your slot receives with @ObservedObject and read session.state.
isValid is true while the SDK’s card number, expiry date, CVV and cardholder name fields all hold valid values. Billing address fields don’t count toward it. While isValid is true, the SDK keeps fieldErrors empty. It clears every entry whenever a field’s validity updates, billing errors included. Use isValid 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

Validation runs inside the SDK’s own field views (the CardFormDefaults building blocks), which also show the field’s error message. The update* methods on PrimerCardFormSession store a value but never produce a validation error. A TextField of your own never produces a FieldError. Keep the SDK field and use the helpers on session.state to add your own UI around it. The example below adds a hint under the CVV field while it has an error.
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’s field views populate fieldErrors when the shopper leaves a field. 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.