reset

fun reset(block: () -> Unit)(source)

Resets the form metadata and executes a custom reset block for synchronization.

This function is specifically designed for scenarios where you manage mutable form values manually (like TextFieldState, MutableState, etc.) and need to synchronize their reset operations with the form metadata reset. The provided block allows you to reset your manually managed mutable values at the same time as the form metadata.

Use Case: When using rememberFormMetaState with manually managed field states, you need a way to reset both the form metadata and your custom field states simultaneously. This function provides that synchronization mechanism.

What this function does:

  1. Executes the provided block (where you reset your mutable values)

  2. Clears all field metadata (errors, dirty flags, touched flags, validation state)

  3. Resets the form submission state based on pre-validation policy

  4. Increments the reset counter (which updates the key property)

Usage pattern:

@Composable
fun MyForm() {
val nameState = rememberTextFieldState()
val emailState = rememberTextFieldState()
val formMeta = rememberFormMetaState()

val formState = remember(formMeta.key) {
FormState(
value = FormData(name = nameState, email = emailState),
meta = formMeta
)
}

// Reset both form metadata and field states synchronously
fun resetForm() {
formMeta.reset {
nameState.clearText()
emailState.clearText()
}
}
}

Parameters

block

A lambda function where you should reset your manually managed mutable values. This block is executed within a Compose snapshot to ensure atomic updates.