Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve web demo input validation #46

Merged
merged 4 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 33 additions & 13 deletions demo/src/jsMain/kotlin/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.sizeIn
Expand Down Expand Up @@ -65,9 +66,11 @@ internal fun App() {
}
) { padding ->
Column(
modifier = Modifier.padding(padding)
.padding(horizontal = 32.dp).padding(bottom = 32.dp)
modifier = Modifier
.fillMaxWidth()
.verticalScroll(rememberScrollState())
.padding(padding)
.padding(horizontal = 32.dp).padding(bottom = 32.dp)
) {
Row(verticalAlignment = Alignment.CenterVertically) {
Text(
Expand Down Expand Up @@ -204,6 +207,12 @@ private fun FileSizeDemo(selectedLanguageCode: String) {
if (it.length < 16) {
myFile = it
}
},
isError = myFile.toLongOrNull() == null,
supportingText = if (myFile.toLongOrNull() == null) {
{ Text("Invalid number") }
} else {
null
}
)
Text(
Expand All @@ -224,11 +233,12 @@ private fun FileSizeDemo(selectedLanguageCode: String) {
TextField(
modifier = Modifier.sizeIn(minWidth = 20.dp),
value = decimals,
onValueChange = {
val updatedDecimals = it.toIntOrNull()
if (updatedDecimals != null && updatedDecimals < 10) {
decimals = it
}
onValueChange = { decimals = it },
isError = decimals.toIntOrNull() == null,
supportingText = if (decimals.toIntOrNull() == null) {
{ Text("Invalid number") }
} else {
null
}
)
}
Expand Down Expand Up @@ -277,6 +287,12 @@ private fun AbbreviationDemo(selectedLanguageCode: String) {
if (it.length < 16) {
myNumber = it
}
},
isError = myNumber.toLongOrNull() == null,
supportingText = if (myNumber.toLongOrNull() == null) {
{ Text("Invalid number") }
} else {
null
}
)
}
Expand All @@ -293,11 +309,12 @@ private fun AbbreviationDemo(selectedLanguageCode: String) {
TextField(
modifier = Modifier.sizeIn(minWidth = 20.dp),
value = decimals,
onValueChange = {
val updatedDecimals = it.toIntOrNull()
if (updatedDecimals != null && updatedDecimals < 10) {
decimals = it
}
onValueChange = { decimals = it },
isError = decimals.toIntOrNull() == null,
supportingText = if (decimals.toIntOrNull() == null) {
{ Text("Invalid number") }
} else {
null
}
)
}
Expand Down Expand Up @@ -392,7 +409,10 @@ private fun DateTimeField(instant: Instant, onUpdate: (Instant) -> Unit) {
error = true
}
},
isError = error
isError = error,
supportingText = if (error) {
{ Text("Invalid date format. Please use ISO-8601 ;-)") }
} else null
)
}

Expand Down
2 changes: 1 addition & 1 deletion docs/composeApp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/composeApp.js.map

Large diffs are not rendered by default.

Loading