Learn about customisation options for the pre-fill billing address checkbox.
val prefillBillingAddressCheckboxConfig = PrefillBillingAddressCheckboxConfig(
countrySelectionComponent = CountrySelectionComponent?,
postcodeComponent = PostcodeComponent?,
addressComponent = AddressComponent?,
shippingAddress = ShippingAddress?,
checked = Boolean,
styles = PrefillBillingAddressCheckboxStyle,
label = String,
initialChecked = Boolean,
style = CheckboxStyle?,
annotatedLabel = AnnotatedString?,
validations = CheckboxValidations
)| Property | Description |
|---|---|
countrySelectionComponentCountrySelectionComponent? | Country selection component to be prefilled when the checkbox is checked. |
postcodeComponentPostcodeComponent? | Postcode component to be prefilled when the checkbox is checked. |
addressComponentAddressComponent? | Address component to be prefilled when the checkbox is checked. |
shippingAddressShippingAddress? | Shipping address data to use for prefill. |
checkedBoolean | Whether the checkbox is initially checked. Defaults to false. |
stylesPrefillBillingAddressCheckboxStyle | Visual style configuration. |
labelString | The label text displayed next to the checkbox. Defaults to "Same as shipping address". |
initialCheckedBoolean | Whether the checkbox is initially checked when created. Inherited from CheckboxConfig. |
styleCheckboxStyle? | Styling configuration for the checkbox's appearance. Inherited from CheckboxConfig. |
annotatedLabelAnnotatedString? | The rich text label with clickable links, used instead of the plain label when provided. Inherited from CheckboxConfig. |
validationsCheckboxValidations | Validation rules and messages for the checkbox component. Inherited from CheckboxConfig. |
data class PrefillBillingAddressCheckboxConfig(
val onToggleChanged: ((Boolean) -> Unit)? = null,
val onFocus: (() -> Unit)? = null,
val onBlur: (() -> Unit)? = null,
val onFocusChange: ((Boolean) -> Unit)? = null,
val onValidationPassed: ((List<ValidationResult>) -> Unit)? = null,
val onValidationFailed: ((List<ValidationResult>) -> Unit)? = null,
val onTriggerFieldValidation: ((ValidationResult) -> Unit)? = null,
val onChange: (() -> Unit)? = null
)| Callback | Description |
|---|---|
onToggleChanged: ((Boolean) -> Unit)? | Event handler for when the toggle state changes. |
onFocus: (() -> Unit)? | Event handler for when the component receives focus. |
onBlur: (() -> Unit)? | Event handler for when the component loses focus. |
onFocusChange: ((Boolean) -> Unit)? | Event handler for when the component's focus state changes. |
onValidationPassed: ((List<ValidationResult>) -> Unit)? | Event handler for when validation passes. |
onValidationFailed: ((List<ValidationResult>) -> Unit)? | Event handler for when validation fails. |
onTriggerFieldValidation: ((ValidationResult) -> Unit)? | Event handler for when field validation is triggered individually. |
onChange: (() -> Unit)? | Event handler for when the field value changes. |
For more information about callbacks, see Events.
import com.pxp.checkout.components.prefillbillingaddresscheckbox.PrefillBillingAddressCheckboxComponent
import com.pxp.checkout.components.prefillbillingaddresscheckbox.PrefillBillingAddressCheckboxConfig
import com.pxp.checkout.components.countryselection.CountrySelectionComponent
import com.pxp.checkout.components.postcode.PostcodeComponent
import com.pxp.checkout.components.address.AddressComponent
import com.pxp.checkout.models.ShippingAddress
import com.pxp.checkout.styles.PrefillBillingAddressCheckboxStyle
// Create shipping address data
val shippingAddress = ShippingAddress(
countryCode = "US",
postalCode = "10001",
address = "123 Main Street"
)
// Optional: Create custom styling
val customStyle = PrefillBillingAddressCheckboxStyle(
colors = PrefillBillingAddressCheckboxStyle.ColorStyles(
checkedColor = Color.Blue,
uncheckedColor = Color.Gray,
checkmarkColor = Color.White
),
textStyles = PrefillBillingAddressCheckboxStyle.TextStyles(
checkedLabelStyle = TextStyle(
color = Color.Blue,
fontSize = 14.sp
),
uncheckedLabelStyle = TextStyle(
color = Color.Black,
fontSize = 14.sp
)
)
)
val config = PrefillBillingAddressCheckboxConfig(
// Component references for prefilling
countrySelectionComponent = countrySelectionComponent,
postcodeComponent = postcodeComponent,
addressComponent = addressComponent,
// Shipping address data source
shippingAddress = shippingAddress,
// Initial state
checked = false,
label = "Same as shipping address",
// Styling (optional)
styles = customStyle,
// Validation (optional)
validations = CheckboxValidations(
required = "Please confirm billing address preference"
)
)
val prefillCheckboxComponent = checkout.createComponent<PrefillBillingAddressCheckboxComponent, PrefillBillingAddressCheckboxConfig>(
type = ComponentType.PREFILL_BILLING_ADDRESS_CHECKBOX,
config = config
)