rememberForm

fun <T> rememberForm(initialValue: T, saver: Saver<T, Any> = autoSaver(), policy: FormPolicy = FormPolicy(), onSubmit: (T) -> Unit): Form<T>

Remembers a form with the given initial value and submission handler.

This function creates and remembers a form instance that manages form state, validation, and submission. The form state is automatically saved and restored across configuration changes.

Usage:

val form = rememberForm(
initialValue = UserData(name = "", email = ""),
onSubmit = { userData ->
// Handle form submission
submitUserData(userData)
}
)

Return

A Form instance that manages the form state and submission.

Parameters

T

The type of the form data.

initialValue

The initial value for the form.

saver

The saver used to save and restore the form state across configuration changes.

policy

The form policy that defines validation behavior and options.

onSubmit

The callback function called when the form is submitted successfully.


fun <T> rememberForm(state: FormState<T>, onSubmit: (T) -> Unit): Form<T>

Remembers a form with the given form state and submission handler.

This overload allows you to provide your own form state instance, giving you more control over state management and persistence.

Usage:

val formState = rememberFormState(initialValue = UserData())
val form = rememberForm(
state = formState,
onSubmit = { userData ->
// Handle form submission
submitUserData(userData)
}
)

Return

A Form instance that manages the form state and submission.

Parameters

T

The type of the form data.

state

The form state to use for this form.

onSubmit

The callback function called when the form is submitted successfully.