Number

The Number field is used for numeric values such as integers, floating-point numbers, decimals, and other JVM numeric types.

By default, KraftAdmin automatically detects numeric properties and renders an appropriate number input. You only need to specify inputType = FormInputType.NUMBER when overriding the default behavior.

ℹ️ Info

KraftAdmin automatically infers numeric fields from the property’s JVM type.

Supported Types

The following Kotlin and Java types are supported:

KotlinJava
Intint / Integer
Longlong / Long
Floatfloat / Float
Doubledouble / Double
Shortshort / Short
Bytebyte / Byte
BigDecimalBigDecimal
BigIntegerBigInteger

Automatic Detection

In most cases no annotation is required.

@Entity
class Product(

    var quantity: Int,

    var price: Double,

    var stock: Long
)

KraftAdmin automatically renders these as numeric inputs.


Explicit Configuration

You can explicitly configure the field using @KraftAdminField.

@KraftAdminField(
    label = "Price",
    inputType = FormInputType.NUMBER
)
var price: Double = 0.0

Required Field

@KraftAdminField(
    required = true,
    validationMessage = "Price is required."
)
var price: Double = 0.0

The field cannot be submitted with an empty value.


Placeholder

@KraftAdminField(
    placeholder = "Enter product price"
)
var price: Double = 0.0

Read-only

@KraftAdminField(
    readonly = true
)
var totalSales: Double = 0.0

The value is displayed but cannot be edited.


Hide from Tables

@KraftAdminField(
    showInTable = false
)
var internalCost: Double = 0.0

Useful for values that should only appear in the edit form.


Sorting

Sorting is enabled by default.

@KraftAdminField(
    sortable = false
)
var score: Double = 0.0

Validation

Numeric fields also support regular expression validation.

@KraftAdminField(
    regex = "^\d+(\.\d{1,2})?$",
    validationMessage = "Maximum two decimal places allowed."
)
var price: Double = 0.0

Grouping

Fields can be organized into logical sections.

@KraftAdminField(
    group = "Pricing"
)
var price: Double = 0.0

Best Practices

💡 Tip

Use Kotlin numeric types directly whenever possible. KraftAdmin automatically selects the correct numeric component without requiring inputType = FormInputType.NUMBER.

⚠️ Warning

Regular expressions validate the textual input before conversion to a numeric value. Ensure your regex matches the expected number format.


Related Properties

PropertyDescription
labelDisplay label
requiredMakes the field mandatory
placeholderInput hint
sortableEnables table sorting
readonlyPrevents editing
showInTableControls table visibility
groupForm section grouping
regexValidation pattern
validationMessageCustom validation message

See Also

  • Text
  • Range
  • Date
  • Select
  • Checkbox