Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Select

Single-value selection from predefined options.

SQLite Storage

TEXT column storing the selected value.

Definition

crap.fields.select({
    name = "status",
    required = true,
    default_value = "draft",
    options = {
        { label = "Draft", value = "draft" },
        { label = "Published", value = "published" },
        { label = "Archived", value = "archived" },
    },
})

Options Format

Each option is a table with:

PropertyTypeDescription
labelstringDisplay text in the admin UI
valuestringStored value in the database

Multi-Value (has_many)

Allow selecting multiple options. Values are stored as a JSON array in a TEXT column.

crap.fields.select({
    name = "categories",
    has_many = true,
    options = {
        { label = "News", value = "news" },
        { label = "Tech", value = "tech" },
        { label = "Sports", value = "sports" },
    },
})

Admin Rendering

Renders as a <select> dropdown. When has_many = true, renders as a multi-select.