Text Fields

Text fields are used for collecting textual information from administrators.

KraftAdmin supports several specialized text input types that provide browser-level validation and optimized keyboards on mobile devices.

ℹ️ Info

If inputType is omitted, KraftAdmin automatically infers TEXT for String properties.


Available Input Types

Input TypeDescription
TEXTStandard single-line text input
TEXTAREAMulti-line text
EMAILEmail address
PASSWORDHidden password field
TELTelephone number
URLWebsite address
SEARCHSearch input
HIDDENHidden form field

Automatic Detection

@Entity
class User(

    var firstName: String,

    var lastName: String
)

KraftAdmin automatically renders these fields as standard text inputs.


Standard Text

@KraftAdminField(
    label = "Full Name"
)
var name: String = ""

Text Area

Use a textarea for long-form content.

@KraftAdminField(
    inputType = FormInputType.TEXTAREA
)
var biography: String = ""

Email

Email fields use browser validation.

@KraftAdminField(
    inputType = FormInputType.EMAIL
)
var email: String = ""

Password

Passwords are masked while typing.

@KraftAdminField(
    inputType = FormInputType.PASSWORD
)
var password: String = ""
⚠️ Warning

Passwords should always be hashed before storage. KraftAdmin only controls the user interface and does not perform password hashing.


Telephone

@KraftAdminField(
    inputType = FormInputType.TEL
)
var phone: String = ""

URL

@KraftAdminField(
    inputType = FormInputType.URL
)
var website: String = ""

Search

@KraftAdminField(
    inputType = FormInputType.SEARCH
)
var keyword: String = ""

Useful for search interfaces and filter forms.


Hidden

@KraftAdminField(
    inputType = FormInputType.HIDDEN
)
var internalId: String = ""

Hidden fields are included in the form but are not visible to users.


Common Configuration

Required

@KraftAdminField(
    required = true
)
var username: String = ""

Placeholder

@KraftAdminField(
    placeholder = "Enter your username"
)
var username: String = ""

Label

@KraftAdminField(
    label = "Display Name"
)
var name: String = ""

Read-only

@KraftAdminField(
    readonly = true
)
var slug: String = ""

Hide from Tables

@KraftAdminField(
    showInTable = false
)
var biography: String = ""

Validation

Use regular expressions to validate text.

@KraftAdminField(
    regex = "^[A-Za-z ]+$",
    validationMessage = "Only alphabetic characters are allowed."
)
var fullName: String = ""

Sensitive Data

Sensitive values are masked in tables.

@KraftAdminField(
    sensitive = true
)
var apiKey: String = ""

Grouping

@KraftAdminField(
    group = "Contact Information"
)
var email: String = ""

Best Practices

💡 Tip

Allow KraftAdmin to infer TEXT for ordinary strings. Only specify an inputType when a specialized control such as EMAIL, PASSWORD, or URL is required.

💡 Tip

Use TEXTAREA for descriptions, articles, comments, and other multi-line content.

⚠️ Warning

Client-side validation improves usability but should never replace server-side validation.


Related Properties

PropertyDescription
labelDisplay label
placeholderPlaceholder text
requiredMakes the field mandatory
regexValidation pattern
validationMessageCustom validation message
readonlyPrevent editing
showInTableControls table visibility
sensitiveMasks sensitive values
groupForm section

See Also

  • Number
  • Date & Time
  • Select
  • Checkbox
  • WYSIWYG