1 min read
Common customisations
Create new fields
If you need to create a new field, for a new country form or for an existing one, you need to:
- Define an id for you new field or reuse an existing one. If you reuse the same id for 2 fields, i.e. same field on different country forms, they will share the same value.
- Initialize your new fields states on GetAddressValidation adding the validation.
- Use getValidationField to get the value of your new field from
SaveAddressFormDTO.addressState.validationFields
, the error fromSaveAddressFormDTO.addressState.errors
and create the Composable with these values.
Modify existing validations
If you want to modify existing field validations, you need to:
- Override GetAddressValidation or the country specific validator.
- Replace on the returning Map the
ValidationMutableStateField
for the field id you want, keeping the same mutableState value.class CustomGetAddressValidation(private val delegate: GetAddressValidation,) : GetAddressValidation {override fun invoke(countryCode: CountryCode?,currentValidationFields: Map<String, ValidationMutableStateField<*>>,): Map<String, ValidationMutableStateField<*>> {val map = delegate(countryCode, currentValidationFields)return map.toMutableMap().apply {this[ID_TO_REPLACE] = ValidationMutableString(value = getValidationField<String>(ID_TO_REPLACE)?.value ?: mutableStateOf(""),validationList = emptyList(), // New validationisMandatory = true,)}}}
Add extra fields to all or specific country forms
The different country forms, and BaseSaveAddressForm, have composable slots to include new fields. To use them, you need to:
- Extend
PoqSaveAddressScreen
and override the functionAddressCountryFormSelector
. - Create your new fields and add them to the appropriate slot included in
SaveAddressFormDTO
.
From PoqSaveAddressScreen.addressCountryFormSelector
you have the choice to include your new fields to all country forms or only when saveAddressFormDTO.addressState.countryCode
matches with the country code you want to modify.
New Country form
SaveAddressScreen supports specific forms per country. If you want to create a new form for a country, you need to:
- Create a new DomainToUiAddressMapper to map your specific country field to
validationFields
. You can use DomainToUiBaseAddressMapper to map common fields. - Create a new UiToDomainAddressMapper to map your specific country field back to the Address model. You can use BaseSaveAddressForm to show common fields.
- Create an object of CustomSaveAddressCountryForm and call register() in your Application.onCreate.
Remove fields from BaseSaveAddressForm
BaseSaveAddressForm, the common Composable to all forms screens, allows remove its fields. To do so you only need to send null on the appropiate label on BaseSaveAddressLabels.
If you need to remove fields from a specific country, you can decorate BaseSaveAddressForm
passing null on the appropiate labels when saveAddressFormDTO.addressState.countryCode
matches with your desired country.