List Element
A form example demonstrating how to use the ListElement in VueForm Laravel to repeat and manage multiple groups of form fields dynamically. Documentation
🧱 Import Class
use VueFormLaravel\Abstracts\VueFormBuilder;
use VueFormLaravel\Elements\Fields\TextElement;
use VueFormLaravel\Elements\Structure\GroupElement;
use VueFormLaravel\Elements\Structure\ListElement;
use VueFormLaravel\Elements\Vueform;
🧩 Example
class ListElementForm extends VueFormBuilder
{
protected function buildForm()
{
return Vueform::build()
->schema([
ListElement::schema([
TextElement::name('item_name')
->label('Item Name')
->rules('required'),
GroupElement::rowWith4Columns([
GroupElement::rowWith4Columns([
TextElement::name('first_name'),
TextElement::name('first_name_old')
]),
]),
])
]);
}
}
⚙️ Allowed Attributes
| Name | Data Type | Default | Example |
|---|---|---|---|
| addClass | array|object|string|function |
null | ListElement::name("name")->addClass() |
| addClasses | object|function |
null | ListElement::name("name")->addClasses() |
| addText | string |
null | ListElement::name("name")->addText() |
| after | object|string|number |
null | ListElement::name("name")->after() |
| before | object|string|number |
null | ListElement::name("name")->before() |
| between | object|string|number |
null | ListElement::name("name")->between() |
| columns | object|string|number |
null | ListElement::name("name")->columns() |
| conditions | array |
null | ListElement::name("name")->conditions() |
| controls | object |
null | ListElement::name("name")->controls() |
| default | array |
null | ListElement::name("name")->default() |
| description | string|object |
null | ListElement::name("name")->description() |
| disabled | boolean|function|array|object |
null | ListElement::name("name")->disabled() |
| displayErrors | boolean |
null | ListElement::name("name")->displayErrors() |
| element | object |
null | ListElement::name("name")->element() |
| fieldName | string|object |
null | ListElement::name("name")->fieldName() |
| formatData | function |
null | ListElement::name("name")->formatData() |
| formatLoad | function |
null | ListElement::name("name")->formatLoad() |
| id | string |
null | ListElement::name("name")->id() |
| info | string|object |
null | ListElement::name("name")->info() |
| infoPosition | string |
null | ListElement::name("name")->infoPosition() |
| initial | number |
null | ListElement::name("name")->initial() |
| inline | boolean |
null | ListElement::name("name")->inline() |
| label | string|object|function |
null | ListElement::name("name")->label() |
| max | number |
null | ListElement::name("name")->max() |
| messages | object |
null | ListElement::name("name")->messages() |
| min | number |
null | ListElement::name("name")->min() |
| name | string|number |
null | ListElement::name("name")->name() |
| object | object |
null | ListElement::name("name")->object() |
| order | string |
null | ListElement::name("name")->order() |
| orderBy | string |
null | ListElement::name("name")->orderBy() |
| overrideClass | array|object|string|function |
null | ListElement::name("name")->overrideClass() |
| overrideClasses | object|function |
null | ListElement::name("name")->overrideClasses() |
| presets | array |
null | ListElement::name("name")->presets() |
| removeClass | array|object|function |
null | ListElement::name("name")->removeClass() |
| removeClasses | object|function |
null | ListElement::name("name")->removeClasses() |
| replaceClass | object|function |
null | ListElement::name("name")->replaceClass() |
| replaceClasses | object|function |
null | ListElement::name("name")->replaceClasses() |
| rules | array|string|object |
null | ListElement::name("name")->rules() |
| size | string |
null | ListElement::name("name")->size() |
| slots | object |
null | ListElement::name("name")->slots() |
| sort | boolean |
null | ListElement::name("name")->sort() |
| storeOrder | string |
null | ListElement::name("name")->storeOrder() |
| submit | boolean |
null | ListElement::name("name")->submit() |
| templates | object |
null | ListElement::name("name")->templates() |
| view | string |
null | ListElement::name("name")->view() |
| views | object |
null | ListElement::name("name")->views() |
⚡ Events
You can define custom list element events Documentation directly in PHP using the ->events() method.
Each event value refers to a JavaScript function name.
These functions must be defined inside:
public/vueform-laravel/vueform-custom.js
This allows you to extend or override default behaviors for your generated VueForm components
| Name | Parameters | Description |
|---|---|---|
reset |
- {component} el$ - the element's component | Triggered when the input is resetted. |
clear |
- {component} el$ - the element's component | Triggered when the input is cleared. |
change |
- {string} newValue - the new value - {string} oldValue - the old value - {component} el$ - the element's component |
Triggered when the element's value is changed. |
add |
- {number} index - the index of the added item - {any} addedValue - the added value - {array} newValue - the element value after the item is added - {component} el$ - the element's component |
Triggered when a new item is added to the list. |
remove |
- {number} index - the index of the removed item - {array} value - the element's value after the item is removed - {component} el$ - the element's component |
Triggered when an item is removed from the list. |
sort |
- {array} value - the element's value after sorting - {number} oldIndex - the old index of the moved element - {number} newIndex - the new index of the moved element - {component} el$ - the moved element's component |
Triggered when items are being sorted by the user, when sort: true. |
beforeCreate |
- {component} el$ - the element's component | Triggered in beforeCreate hook. |
created |
- {component} el$ - the element's component | Triggered in created hook. |
beforeMount |
- {component} el$ - the element's component | Triggered in beforeMount hook. |
mounted |
- {component} el$ - the element's component | Triggered in mounted hook. |
beforeUpdate |
- {component} el$ - the element's component | Triggered in beforeUpdate hook. |
updated |
- {component} el$ - the element's component | Triggered in updated hook. |
beforeUnmount |
- {component} el$ - the element's component | Triggered in beforeUnmount (or beforeDestroy in Vue 2) hook. |
unmounted |
- {component} el$ - the element's component | Triggered in unmounted (or destroyed in Vue 2) hook. |
🔔 Example Usage of event (PHP)
ListElement::name('example')
->events([
'reset' => 'handleReset',
'clear' => 'handleClear',
'change' => 'handleChange',
'add' => 'handleAdd',
'remove' => 'handleRemove',
'sort' => 'handleSort',
'beforeCreate' => 'handleBeforeCreate',
'created' => 'handleCreated',
'beforeMount' => 'handleBeforeMount',
'mounted' => 'handleMounted',
'beforeUpdate' => 'handleBeforeUpdate',
'updated' => 'handleUpdated',
'beforeUnmount' => 'handleBeforeUnmount',
'unmounted' => 'handleUnmounted',
])
🔔 Example Usage of event(JavaScript)
function handleReset(el$) {
// Your code here
}
function handleClear(el$) {
// Your code here
}
function handleChange(newValue, oldValue, el$) {
// Your code here
}
function handleAdd({number} index, {any} addedValue, newValue, el$) {
// Your code here
}
function handleRemove({number} index, value, el$) {
// Your code here
}
function handleSort(value, {number} oldIndex, {number} newIndex, el$) {
// Your code here
}
function handleBeforeCreate(el$) {
// Your code here
}
function handleCreated(el$) {
// Your code here
}
function handleBeforeMount(el$) {
// Your code here
}
function handleMounted(el$) {
// Your code here
}
function handleBeforeUpdate(el$) {
// Your code here
}
function handleUpdated(el$) {
// Your code here
}
function handleBeforeUnmount(el$) {
// Your code here
}
function handleUnmounted(el$) {
// Your code here
}
⚡ Slots
The following slots Documentation are available for this element:
| Name | Scope | Description |
|---|---|---|
label |
- {component} el$ - the element's component | Renders a label for the element in ElementLabel component. |
info |
- {component} el$ - the element's component | Renders an info icon in ElementInfo component next the the element label. When the icon is hovered it shows the content of this slot. The element needs to have a label to render this. |
required |
- | |
description |
- {component} el$ - the element's component | Renders description for the element in ElementDescription component. |
before |
- {component} el$ - the element's component | Renders an ElementText component before the list. |
between |
- {component} el$ - the element's component | Renders an ElementText component after the list and before description. |
after |
- {component} el$ - the element's component | Renders an ElementText component after the description and error. |
⚙️ Available Static Methods
| Method | Description |
|---|---|
schema |
This method generates a List Element in VueForm, where each item in the provided |