copper-leaf / copper-leaf/kotlin-json-forms
Bug: String being casted to Integer
- Dominant language
- Kotlin
- Stars
- 16
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
thanks for this nice library.
I found a bug. When I generate text field from ui schema which expects `string` type, and i write number inside, it will not pass (with error text that it must be string).
This is wrong since my text field should be a telephone number "+420777666555", but with the casting it is changed to 420777666555, and this does not satisfy my schema.
The bug is in file com.copperleaf.forms.compose.widgets.material.textFieldWidget.kt
See below where i commented the line with the bug.
```
val updatableText = rememberUpdatableText(
initialValue = currentValue,
mapStateToText = mapStateToText,
onTextChange = { value ->
// send the value as a well-formed T value, if possible. Otherwise, still send the data to the ViewModel,
// but as a string
// updateFormState(value.toIntOrNull() ?: value) //BUG StringControl.control() should not use this
updateFormState(value) // correction
}
)
```
The StringControl.control() below uses the code above, but we want String, so it should not be cast to Int.
```
public fun StringControl.control(): Registered = uiControl {
textFieldWidget(
defaultValue = "",
mapper = { it.jsonPrimitive.content },
mapStateToText = { it },
)
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.