From ae99a4f65f42de39eee03cc04430aa072f8635ef Mon Sep 17 00:00:00 2001 From: KrugarValdes Date: Fri, 27 Jun 2025 16:48:01 +0600 Subject: [PATCH] [~]Fix: Add input filtering for phone number field --- .../office/elevator/components/UserInfoTextField.kt | 12 ++++++++---- .../authorization_phone/AuthorizationPhoneScreen.kt | 4 ++++ .../ui/profile/editProfile/ProfileEditScreen.kt | 7 +++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/band/effective/office/elevator/components/UserInfoTextField.kt b/composeApp/src/commonMain/kotlin/band/effective/office/elevator/components/UserInfoTextField.kt index 1f3733df..1a687602 100644 --- a/composeApp/src/commonMain/kotlin/band/effective/office/elevator/components/UserInfoTextField.kt +++ b/composeApp/src/commonMain/kotlin/band/effective/office/elevator/components/UserInfoTextField.kt @@ -44,16 +44,20 @@ fun UserInfoTextField( visualTransformation: VisualTransformation = VisualTransformation.None, text: String, keyboardType: KeyboardType = KeyboardType.Text, - onValueChange: (String) -> Unit + onValueChange: (String) -> Unit, + filterInput: (String) -> String = { it } ) { var textValue by remember { mutableStateOf(text) } OutlinedTextField( value = textValue, modifier = modifier.fillMaxWidth(), - onValueChange = { - textValue = it - onValueChange(it) + onValueChange = { input -> + val filtered = filterInput(input) + if (filtered != textValue) { + textValue = filtered + onValueChange(filtered) + } }, shape = RoundedCornerShape(12.dp), singleLine = true, diff --git a/composeApp/src/commonMain/kotlin/band/effective/office/elevator/ui/authorization/authorization_phone/AuthorizationPhoneScreen.kt b/composeApp/src/commonMain/kotlin/band/effective/office/elevator/ui/authorization/authorization_phone/AuthorizationPhoneScreen.kt index 8ba987c2..3202c9ad 100644 --- a/composeApp/src/commonMain/kotlin/band/effective/office/elevator/ui/authorization/authorization_phone/AuthorizationPhoneScreen.kt +++ b/composeApp/src/commonMain/kotlin/band/effective/office/elevator/ui/authorization/authorization_phone/AuthorizationPhoneScreen.kt @@ -167,6 +167,10 @@ private fun AuthorizationPhoneComponent( AuthorizationPhoneStore.Intent.PhoneNumberChanged(phoneNumber = it) ) }, + filterInput = { newText -> + newText + .filter { it.isDigit() } + .take(10)}, modifier = Modifier .fillMaxWidth() .wrapContentHeight() diff --git a/composeApp/src/commonMain/kotlin/band/effective/office/elevator/ui/profile/editProfile/ProfileEditScreen.kt b/composeApp/src/commonMain/kotlin/band/effective/office/elevator/ui/profile/editProfile/ProfileEditScreen.kt index de2b75e2..6f44708a 100644 --- a/composeApp/src/commonMain/kotlin/band/effective/office/elevator/ui/profile/editProfile/ProfileEditScreen.kt +++ b/composeApp/src/commonMain/kotlin/band/effective/office/elevator/ui/profile/editProfile/ProfileEditScreen.kt @@ -176,8 +176,11 @@ private fun ProfileEditScreenContent( text = phoneNumberText.value, error = isErrorPhone, visualTransformation = PhoneMaskTransformation, - keyboardType = KeyboardType.Phone, - onValueChange = { phoneNumberText.value = it } + onValueChange = { phoneNumberText.value = it }, + filterInput = { newText -> + newText + .filter { it.isDigit() } + .take(10)} ) } -- GitLab