form-conductor
form-conductor copied to clipboard
Way to set default value
I wonder if there is a way to set some initial data to fields in compose variant?
I have code like this:
@Composable
fun MySuperComponent() {
Column {
MySuperFetch( SomeRequest() ) { data ->
form(SomeForm::class) {
field(SomeForm::someField) {
TextField(
label = { Text("Cool Field") },
value = state.value?.value.orEmpty(),
onValueChange = this::setField
)
}
}
}
}
}
I've found this way working, but it doesn't seems good.
@Composable
fun MySuperComponent() {
Column {
MySuperFetch( SomeRequest() ) { data ->
form(SomeForm::class) {
field(SomeForm::someField) {
+ val fld = this
+ LaunchedEffect(Unit) {
+ fld.setField(data.someField)
+ }
TextField(
label = { Text("Cool Field") },
value = state.value?.value.orEmpty(),
onValueChange = this::setField
)
}
}
}
}
}
Is there better way? f.e. like this?
@Composable
fun MySuperComponent() {
Column {
MySuperFetch( SomeRequest() ) { data ->
form(SomeForm::class) {
- field(SomeForm::someField) {
+ field(SomeForm::someField, defaultValue = data.someField) {
TextField(
label = { Text("Cool Field") },
value = state.value?.value.orEmpty(),
onValueChange = this::setField
)
}
}
}
}
}