---
title: "byValue"
description: "Creates an [InputTransformation] from a function that accepts both the current and proposed
[TextFieldCharSequence] and returns the [TextFieldCharSequence] to use for the field.

[transformation] can return either `current`, `proposed`, or a completely different value.

The selection or cursor will be updated automatically. For more control of selection implement
[InputTransformation] directly."
type: "function"
---

<div class='type'>Function</div>


<a id='references'></a>
<div class='sourceset sourceset-common'>Common</div>


```kotlin
fun InputTransformation.byValue(
    transformation: (current: CharSequence, proposed: CharSequence) -> CharSequence
): InputTransformation
```


Creates an `InputTransformation` from a function that accepts both the current and proposed
`TextFieldCharSequence` and returns the `TextFieldCharSequence` to use for the field.

`transformation` can return either `current`, `proposed`, or a completely different value.

The selection or cursor will be updated automatically. For more control of selection implement
`InputTransformation` directly.



## Code Examples
### BasicTextFieldInputTransformationByValueChooseSample
```kotlin
@Composable
fun BasicTextFieldInputTransformationByValueChooseSample() {
    val state = remember { TextFieldState() }
    BasicTextField(
        state,
        // Reject whitespace.
        inputTransformation =
            InputTransformation.byValue { current, proposed ->
                if ("""\s""".toRegex() in proposed) current else proposed
            },
    )
}
```
### BasicTextFieldInputTransformationByValueReplaceSample
```kotlin
@Composable
fun BasicTextFieldInputTransformationByValueReplaceSample() {
    val state = remember { TextFieldState() }
    BasicTextField(
        state,
        // Convert tabs to spaces.
        inputTransformation =
            InputTransformation.byValue { _, proposed ->
                proposed.replace("""\t""".toRegex(), "  ")
            },
    )
}
```

