Grid Element

A form example demonstrating how to use the GridElement in VueForm Laravel to organize form elements into responsive rows and columns using a grid layout. Documentation


🧱 Import Class

use VueFormLaravel\Abstracts\VueFormBuilder;
use VueFormLaravel\Elements\Static\ButtonElement;
use VueFormLaravel\Elements\Static\StaticElement;
use VueFormLaravel\Elements\Structure\GridElement;
use VueFormLaravel\Elements\Vueform;

🧩 Example

class GridElementForm extends VueFormBuilder
{
    protected function buildForm()
    {
        return Vueform::build()
            ->schema([
                StaticElement::h1('Grid Element Form row with various column layouts')
                    ->addClass('mb-4'),
                StaticElement::p('This form demonstrates the use of GridElement to create structured multi-column layouts. You can arrange form fields into rows with configurable column counts (1, 2, 3, 4, or 6 columns). Each row can contain different input types such as text, select, date, and slider elements, enabling clean and organized form designs. Ideal for forms that require responsive and visually structured data entry.')
                    ->addClass('mb-4'),
                StaticElement::hr(),
                StaticElement::h3('Row with 1 Column')->addClass('mb-2'),
                GridElement::rowWith1Columns([
                    ['type' => 'text', 'name' => 'a', 'placeholder' => 'A'],
                    ['type' => 'select', 'items' => [1, 2, 3], 'name' => 'b', 'placeholder' => 'B'],
                    ['type' => 'date', 'name' => 'c', 'placeholder' => 'C'],
                    ['type' => 'slider', 'name' => 'd']
                ]),
                StaticElement::hr(),
                StaticElement::h3('Row with 2 Columns')->addClass('mb-2'),
                GridElement::rowWith2Columns([
                    ['type' => 'text', 'name' => 'e', 'placeholder' => 'E'],
                    ['type' => 'select', 'items' => [1, 2, 3], 'name' => 'f', 'placeholder' => 'F'],
                    ['type' => 'date', 'name' => 'g', 'placeholder' => 'G'],
                    ['type' => 'slider', 'name' => 'h']
                ]),
                StaticElement::hr(),
                StaticElement::h3('Row with 3 Columns')->addClass('mb-2'),
                GridElement::rowWith3Columns([
                    ['type' => 'text', 'name' => 'e', 'placeholder' => 'E'],
                    ['type' => 'select', 'items' => [1, 2, 3], 'name' => 'f', 'placeholder' => 'F'],
                    ['type' => 'date', 'name' => 'g', 'placeholder' => 'G'],
                    ['type' => 'slider', 'name' => 'h']
                ]),
                StaticElement::hr(),
                StaticElement::h3('Row with 4 Columns')->addClass('mb-2'),
                GridElement::rowWith4Columns([
                    ['type' => 'text', 'name' => 'e', 'placeholder' => 'E'],
                    ['type' => 'select', 'items' => [1, 2, 3], 'name' => 'f', 'placeholder' => 'F'],
                    ['type' => 'date', 'name' => 'g', 'placeholder' => 'G'],
                    ['type' => 'slider', 'name' => 'h']
                ]),
                StaticElement::hr(),

                ButtonElement::submitButton()
            ]);
    }

    public static function formData($request)
    {
        $request->validate([
            'e' => 'required'
        ]);

        return response()->json([
            'status' => 'success'
        ]);
    }
}

⚙️ Allowed Attributes

Name Data Type Default Example
addClass array|object|string|function null GridElement::name("name")->addClass()
addClasses object|function null GridElement::name("name")->addClasses()
after object|string|number null GridElement::name("name")->after()
align string null GridElement::name("name")->align()
before object|string|number null GridElement::name("name")->before()
between object|string|number null GridElement::name("name")->between()
colHeader boolean null GridElement::name("name")->colHeader()
cols number null GridElement::name("name")->cols()
columns object|string|number null GridElement::name("name")->columns()
conditions array null GridElement::name("name")->conditions()
default object null GridElement::name("name")->default()
description string|object null GridElement::name("name")->description()
displayErrors boolean null GridElement::name("name")->displayErrors()
fieldName string|object null GridElement::name("name")->fieldName()
formatData function null GridElement::name("name")->formatData()
formatLoad function null GridElement::name("name")->formatLoad()
grid array null GridElement::name("name")->grid()
id string null GridElement::name("name")->id()
info string|object null GridElement::name("name")->info()
infoPosition string null GridElement::name("name")->infoPosition()
inline boolean null GridElement::name("name")->inline()
label string|object|function null GridElement::name("name")->label()
maxWidth string|number null GridElement::name("name")->maxWidth()
messages object null GridElement::name("name")->messages()
minWidth string|number null GridElement::name("name")->minWidth()
name string|number null GridElement::name("name")->name()
overrideClass array|object|string|function null GridElement::name("name")->overrideClass()
overrideClasses object|function null GridElement::name("name")->overrideClasses()
presets array null GridElement::name("name")->presets()
removeClass array|object|function null GridElement::name("name")->removeClass()
removeClasses object|function null GridElement::name("name")->removeClasses()
replaceClass object|function null GridElement::name("name")->replaceClass()
replaceClasses object|function null GridElement::name("name")->replaceClasses()
rowHeader boolean null GridElement::name("name")->rowHeader()
rows number null GridElement::name("name")->rows()
rules array|string|object null GridElement::name("name")->rules()
scrollable boolean null GridElement::name("name")->scrollable()
size string null GridElement::name("name")->size()
slots object null GridElement::name("name")->slots()
submit boolean null GridElement::name("name")->submit()
templates object null GridElement::name("name")->templates()
valign string null GridElement::name("name")->valign()
view string null GridElement::name("name")->view()
views object null GridElement::name("name")->views()
widths array null GridElement::name("name")->widths()

⚡ Events

You can define custom grid 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.
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)

GridElement::name('example')
    ->events([
        'reset' => 'handleReset',
        'clear' => 'handleClear',
        'change' => 'handleChange',
        '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 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 grid.
between - {component} el$ - the element's component Renders an ElementText component after the grid and before description.
after - {component} el$ - the element's component Renders an ElementText component after the description and error.

⚙️ Available Static Methods

Method Description
rowWith1Columns Arrange the given data into a single column row.
rowWith2Columns Arrange the given data into a two-column row.
rowWith3Columns Arrange the given data into a three-column row.
rowWith4Columns Arrange the given data into a four-column row.
rowWith6Columns Arrange the given data into a six-column row.