Forms

Display a form with fields mapped to model attributes, define custom actions, validations, etc.

View form.yaml example
# /flatpack/posts/form.yaml

header:
  title:
    type: heading
    size: large

toolbar:
  save:
    type: button
    label: Save
    action: save
    shortcut: s

main:
  title:
    label: Title
    placeholder: Post title
    rules: required|string

  slug:
    label: Slug
    placeholder: Post title slug
    span: 1

  category:
    label: Category
    type: relation
    relation:
      name: category
      display: name
    span: 1

  body:
    label: Post body
    type: textarea
    group: more

sidebar:
  created_at:
    label: Created
    type: datetimepicker
    span: 1
    group: Info

  updated_at:
    label: Updated
    type: datetimepicker
    span: 1
    group: Info

Content slots

By default, if you don't want (or don't need) to use content slots, you can simply put all your fields under the same fields definition.

# /flatpack/posts/form.yaml

fields:
  # All form fields in one boxed fieldset

Alternatively, an advanced version of form.yaml composition can be defined using form content slots.

SlotDescriptionAllowed field types
headerHeading fieldsheading or editable
toolbarAction buttonsbutton or link
mainMain field setAny form field type
sidebarSidebar fieldsAny form field type

Example:

# /flatpack/posts/form.yaml

header:
  # Heading fields

toolbar:
  # Action buttons

main:
  # Main field set

sidebar:
  # Sidebar fields

Form Fields

Field options

OptionDescription
typeForm field type (see Field Types)
labelField label text.
placeholderInput placeholder text.
groupName of the grouping box to include the field within.
spanhalf for 50% width, full for 100% width.
rulesString of validation rules (uses Laravel Validation rulesopen in new window)

Field types

Text input

text - renders a single line text input box. This is the default type used if none is specified.

Email input

email - renders a single line email input box.

Textarea input

textarea - renders a textarea input box.

Datetime picker

datetime-picker - renders a datetime picker input box.

Editor

editor - renders a WYSIWYG text editor using CkEditoropen in new window

Block editor

block-editor - renders a next generation block styled editor using Editor.jsopen in new window

Heading

heading - renders a read-only heading field.

Editable

editable - renders a label (or heading) that becomes a text input on click.

Relation

relation - renders a list of checkboxes.

Tag input

taginput - renders a field with tags for related records.

Button

button - renders a button.

Form Validation

Validation rules can be applied to each form field by defining the rules option. This option accepts all the available Validation rulesopen in new window provided by Laravel.