Skip to content

Text Field

The text field is a key component of any form, allowing the user to input free text

Validation

The TextField can have a String validator provided. Both parameters passed to the validate function will be the raw string.

Common Validators

  • NotEmptyValidator
  • MinLengthValidator
  • MaxLengthValidator
  • NumberOnlyValidator
  • RegexValidator
  • EveryCharacterValidator

Default usage

Along with common fields the default text field includes multiple styling options:

Field Type Default Description Notes
hint Any? null The hint field is displayed continuously no matter the value of the form field. It should give the user a prompt as to what to enter Will be converted to String using asDisplayString
modifier Modifier Modifier.fillMaxWidth() Modifier to apply to the text field.
placeholder Any? null Value to display in the field if no value is populated. Will be converted to String using asDisplayString
leadingIcon (@Composable ()->Unit)? null Icon to display at the start of the field.
trailingIcon (@Composable ()->Unit)? null Icon to display at the end of the form field.
isLast Boolean false If this text field is the last field in the form in the UI. When this is passed as false, an IME action on the keyboard will allow advance to the next text based field, otherwise a done IME action will be displayed.
keyboardOptions KeyboardOptions? null Use this to modify the behaviour of the keyboard used when entering text into this field.
prefix Any "" A static prefix to show in the text field. This will not be included in the value. Will be converted to String using asDisplayString
readOnly Boolean false If the field should be disabled
style FormFieldStyle LocalFormFieldStyle.current Allows styling of the text box to override the default
onValueChange (TextFieldValue)->Unit {} Gives the option to observe the value of only this text field changing, for cases where this field is a part of another field.