ExpirationDateTextField
A PCI-compliant text field component for entering card expiration dates. This component provides a secure input field that handles card expiration dates with automatic formatting and validation.
The component supports both short (MM/YY) and long (MM/YYYY) date formats, automatically formats the input with the appropriate separator, and validates the date against current date and format rules.
Parameters
Optional modifier for customizing the field's appearance and behavior
The PCIFieldState that manages the expiration date input value
Callback for handling ExpirationDateTextFieldEvents triggered during input
The format to use for the expiration date (short or long)
Whether the field is enabled for input
Whether the field is read-only (can be focused but not edited)
Composable for customizing the field's visual appearance
Style configuration for the field's typography
Configuration for the software keyboard
Brush for painting the text cursor
See also
Samples
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.mercadopago.sdk.android.core.sample.Sampled
import com.mercadopago.sdk.android.coremethods.ui.components.textfield.expirationdate.ExpirationDateFormat
import com.mercadopago.sdk.android.coremethods.ui.components.textfield.expirationdate.ExpirationDateTextField
import com.mercadopago.sdk.android.coremethods.ui.components.textfield.pcitextfield.PCIFieldState
import com.mercadopago.sdk.android.coremethods.ui.components.textfield.pcitextfield.rememberPCIFieldState
fun main() {
//sampleStart
// Adding a decoration in the component with custom mask
// Create a PCIFieldState to use in input
val state: PCIFieldState = rememberPCIFieldState()
ExpirationDateTextField(
state = state,
onEvent = { _ ->
// call viewmodel passing the events to handle the calls
},
// Pass the current date format
dateFormat = ExpirationDateFormat.ShortFormat,
decorationBox = { innerTextField ->
// Adding the inner text inside a box with a border
Box(
modifier = Modifier.border(
width = 2.dp,
color = Color.Black,
shape = RoundedCornerShape(10.dp),
),
) {
// Don`t forget to call the innerTextField()
innerTextField()
}
},
)
//sampleEnd
}