Form

fun <T : Any> Form(onSubmit: suspend (T) -> Unit, initialValue: T, modifier: Modifier = Modifier, onError: (err: Throwable) -> Unit? = null, saver: Saver<T, Any> = autoSaver(), key: Any? = null, policy: FormPolicy = FormPolicy.Default, coroutineScope: CoroutineScope = rememberCoroutineScope(), content: @Composable FormScope<T>.() -> Unit)

A Form to manage the state and actions of input fields, and create a child block of FormScope.

Usage:

Form(
onSubmit = {
// Handle submit
},
initialValue = "",
policy = FormPolicy.Minimal
) { // this: FormScope<String>
..
}

Note: If you are expecting state restoration on the Android platform, please check if the type specified in initialValue is restorable. Inside the Form, rememberSaveable is used to manage input values, and runtime errors will be thrown from the API for unsupported types.

Parameters

T

The type of the form value.

onSubmit

The submit handler to call when the form is submit.

initialValue

The initial value of the form.

modifier

The modifier to apply to this layout node.

onError

The error handler to call when an error occurs on submit.

saver

The saver to save and restore the form state.

key

The key to reset the form state.

policy

The policy to apply to the form.

coroutineScope

The coroutine scope to launch the submit handler.

content

The content block to create the child block of FormScope.