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.
Slot | Description | Allowed field types |
---|---|---|
header | Heading fields | heading or editable |
toolbar | Action buttons | button or link |
main | Main field set | Any form field type |
sidebar | Sidebar fields | Any 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
Option | Description |
---|---|
type | Form field type (see Field Types) |
label | Field label text. |
placeholder | Input placeholder text. |
group | Name of the grouping box to include the field within. |
span | half for 50% width, full for 100% width. |
rules | String of validation rules (uses Laravel Validation rules) |
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 CkEditor
Block editor
block-editor
- renders a next generation block styled editor using Editor.js
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 rules provided by Laravel.