Radio Element

A form example demonstrating how to use the RadioElement field in VueForm Laravel to allow users to select a single option from multiple radio choices in a Laravel form. Documentation


🧱 Import Class

use VueFormLaravel\Abstracts\VueFormBuilder;
use VueFormLaravel\Elements\Fields\RadioElement;
use VueFormLaravel\Elements\Vueform;

🧩 Example

class RadioElementForm extends VueFormBuilder
{
    protected function buildForm()
    {
        return Vueform::build()
            ->schema([
                RadioElement::name('terms_and_conditions')
                    ->description('Do you agree to the terms and conditions?')
            ]);
    }
}

⚙️ Allowed Attributes

Name Data Type Default Example
addClass array|object|string|function null RadioElement::name("name")->addClass()
addClasses object|function {} RadioElement::name("name")->addClasses()
after object|string|number null RadioElement::name("name")->after()
align string undefined RadioElement::name("name")->align()
before object|string|number null RadioElement::name("name")->before()
between object|string|number null RadioElement::name("name")->between()
columns object|string|number null RadioElement::name("name")->columns()
conditions array [] RadioElement::name("name")->conditions()
default string|number null RadioElement::name("name")->default()
description string|object null RadioElement::name("name")->description()
disabled boolean|function|array|object false RadioElement::name("name")->disabled()
displayErrors boolean true RadioElement::name("name")->displayErrors()
fieldName string|object name label
formatData function null RadioElement::name("name")->formatData()
formatLoad function null RadioElement::name("name")->formatLoad()
id string null RadioElement::name("name")->id()
info string|object null RadioElement::name("name")->info()
infoPosition string right RadioElement::name("name")->infoPosition()
inline boolean false RadioElement::name("name")->inline()
label string|object|function null RadioElement::name("name")->label()
messages object {} RadioElement::name("name")->messages()
name string|number undefined RadioElement::name("name")->name()
overrideClass array|object|string|function null RadioElement::name("name")->overrideClass()
overrideClasses object|function {} RadioElement::name("name")->overrideClasses()
presets array [] RadioElement::name("name")->presets()
radioName string null RadioElement::name("name")->radioName()
radioValue boolean|string|number 1 RadioElement::name("name")->radioValue()
removeClass array|object|function null RadioElement::name("name")->removeClass()
removeClasses object|function {} RadioElement::name("name")->removeClasses()
replaceClass object|function null RadioElement::name("name")->replaceClass()
replaceClasses object|function {} RadioElement::name("name")->replaceClasses()
rules array|string|object null RadioElement::name("name")->rules()
size string undefined RadioElement::name("name")->size()
slots object {} RadioElement::name("name")->slots()
standalone boolean false RadioElement::name("name")->standalone()
submit boolean true RadioElement::name("name")->submit()
templates object {} RadioElement::name("name")->templates()
text string|object null RadioElement::name("name")->text()
view string undefined RadioElement::name("name")->view()
views object {} RadioElement::name("name")->views()

⚡ Events

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

RadioElement::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
default - {component} el$ - the element's component Renders a label for the radio.
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 radio.
between - {component} el$ - the element's component Renders an ElementText component after the radio and before description.
after - {component} el$ - the element's component Renders an ElementText component after the description and error.