Skip to content

Field types

Thomas van der Veen edited this page Jul 9, 2020 · 13 revisions

The type property will allow you to control how a field should behave.

The following field types are available:

Type Value
Input 'text' 'date' '...'
Checkbox 'checkbox'
Entry select 'entry_select'
Fields 'fields'
File 'file'
Image 'image'
Model select 'model_select'
Multi entry select 'multi_entry_select'
Multi model select 'multi_model_select'
Multi select 'multi_select'
Radio 'radio'
Select 'select'
Textarea 'textarea'



Default

By default all fields will be handled by the input field. This means this package will use this type whenever a value for type in the field configuration is used that has not been configured in the cms.fields.classes array.




Input

Usage: 'type' => 'text'|'date'|...
Class: InputField

This field is focused on rendering an <input> element. It will use the value of type that has been configured in your field configuration as the type attribute of the <input> element.

'type' => 'date' will lead to <input type="date">. All possible input types could be found here.

Remeber that this field is used as fallback when no other field type can be found in the configured cms.fields.classes.

Additional configuration

This field allows additional configuration in the config property.

Property Type Description
input_attributes array An array that is used to pass on additional attributes to the rendered <input> element. All possible attributes could for example be found here.



Checkbox

Usage: 'type' => 'checkbox'
Class: CheckableField




Entry select

Usage: 'type' => 'entry_select'
Class: EntrySelectField

This field will render a <select> element with <option> that represent entries of the configured entry_type.

Additional configuration

This field allows additional configuration in the config property.

Property Type Description
entry_type string A type of entry that is used to fetch from the database.
input_attributes array An array that is used to pass on additional attributes to the rendered <select> element. All possible attributes could for example be found here.
list_item_label_key string A string of a property name from the model that is used to display as option label. This value can be dot notated to retrieve deep properties.
query_constraint callable A callback that is used to alter the query that fetches records from the database. Eg: 'query_constraint' => function ($q) { $q->limit(15); }



Fields

Usage: 'type' => 'fields'
Class: FieldsField

A field that will render child fields.

Additional configuration

This field allows additional configuration in the config property.

Property Type Description
fields array An array of fields configured exactly the same way as how one would do for entries.



File

Usage: 'type' => 'file'
Class: FileField

A field that will render an input where the user can select a file to upload.

Additional configuration

This field allows additional configuration in the config property.

Property Type Description
file_path string A path to a directory in your default storage disk where the files should be stored.

Image

Usage: 'type' => 'image'
Class: ImageField

A field that will render an input where the user can select an image to upload. The selected image is previewed.

Additional configuration

This field allows additional configuration in the config property.

Property Type Description
image_path string A path to a directory in your default storage disk where the images should be stored.
preview_height string|integer The max height of the container in which the image should be previewed. The image itself will be contained in the height of the container
preview_width string|integer The max width of the container in which the image should be previewed. The image itself will be contained in the width of the container



Model select

Usage: 'type' => 'model_select'
Class: ModelSelectField

This field will render a <select> element with <option> that represent database records of the configured model_class.

Additional configuration

This field allows additional configuration in the config property.

Property Type Description
list_item_label_key string A string of a property name from the model that is used to display as option label. This value can be dot notated to retrieve deep properties.
input_attributes array An array that is used to pass on additional attributes to the rendered <select> element. All possible attributes could for example be found here.
model_class string A class name of the model that is used to fetch records from the database
query_constraint callable A callback that is used to alter the query that fetches records from the database. Eg: 'query_constraint' => function ($q) { $q->limit(15); }



Multi entry select

Usage: 'type' => 'multi_entry_select'
Class: MultiEntrySelectField

A field that renders a dropdown where the user can select multiple entries. This field is a combination of the entry select and multi select fields.

Additional configuration

This field allows additional configuration in the config property.

Property Type Description
entry_type string A type of entry that is used to fetch from the database.
list_item_label_key string A string of a property name from the model that is used to display as option label. This value can be dot notated to retrieve deep properties.
query_constraint callable A callback that is used to alter the query that fetches records from the database. Eg: 'query_constraint' => function ($q) { $q->limit(15); }



Multi model select

Usage: 'type' => 'multi_model_select'
Class: MultiModelSelectField

A field that renders a dropdown where the user can select multiple models. This field is a combination of the model select and multi select fields.

Additional configuration

This field allows additional configuration in the config property.

Property Type Description
list_item_label_key string A string of a property name from the model that is used to display as option label. This value can be dot notated to retrieve deep properties.
model_class string A class name of the model that is used to fetch records from the database
query_constraint callable A callback that is used to alter the query that fetches records from the database. Eg: 'query_constraint' => function ($q) { $q->limit(15); }



Multi select

Usage: 'type' => 'multi_select'
Class: MultiSelectField

A field that renders a dropdown where the user can select multiple options.

Additional configuration

This field allows additional configuration in the config property.

Property Type Description
list array An array of options that will be rendered in the dropdown where the key is the value that is being stored and the value is the label being displayed.



Radio

Usage: 'type' => 'radio'
Class: CheckableField




Select

Usage: 'type' => 'select'
Class: SelectField

This field will render a <select> element with <option> elements that are configured in the list property.

Additional configuration

This field allows additional configuration in the config property.

Property Type Description
input_attributes array An array that is used to pass on additional attributes to the rendered <select> element. All possible attributes could for example be found here.
list array An array of options that will be rendered as <option> elements where the key is the value that is being stored and the value is the label being displayed.



Textarea

Usage: 'type' => 'textarea'
Class: TextAreaField

A field that will render a <textarea> element.

Additional configuration

This field allows additional configuration in the config property.

Property Type Description
input_attributes array An array that is used to pass on additional attributes to the rendered <textarea> element. All possible attributes could for example be found here.

Clone this wiki locally