Skip to content

Submit ​

Basic Usage ​

The Submit field renders a submit button. Pass the button label to the make method:

php
use InertiaUI\Forms\Fields\Submit;

Submit::make('Save Entry');

Without a label, the button reads "Submit":

php
Submit::make();

Label ​

To change the label after creating the field, you may use the label method:

php
Submit::make()->label('Save Changes');

Appearance ​

The variant, size, width, and icon methods change how the button looks.

Variants ​

Six visual variants are available:

VariantDescription
primarySolid blue button (default)
secondaryMuted/gray button
dangerRed button for destructive actions
outlineBordered, transparent background
ghostNo border, minimal styling
linkLooks like a text link
Example
php
Submit::make('Save')->primary();
Submit::make('Cancel')->secondary();
Submit::make('Delete')->danger();
Submit::make('Save Draft')->outline();
Submit::make('Skip')->ghost();
Submit::make('Learn More')->link();

The variant method accepts the same names:

php
Submit::make('Save')->variant('primary');

Size ​

Three size helpers are available: sm, md, and lg. The default size is md.

Example
php
Submit::make('Save')->sm();
Submit::make('Save')->md();
Submit::make('Save')->lg();

The size method accepts these sizes too, and also accepts xs and xl:

php
Submit::make('Save')->size('lg');
Submit::make('Save')->size('xs');

Full Width ​

To make the button span the full width of its container, call the fullWidth method:

Example
php
Submit::make('Create Account')->fullWidth();

Icons ​

To add an icon to the button, pass an icon name to the icon method. The frontend icon resolver turns the name into a component. See Icons for the resolver setup.

Example
php
Submit::make('Save')->icon('SaveIcon');

Submit::make('Next')
    ->icon('ArrowRightIcon')
    ->iconPosition('right')
    ->outline();

Submit::make('Delete')
    ->icon('Trash2Icon')
    ->danger();

Icon Position ​

The icon appears on the left by default. To place it on the right, pass right to the iconPosition method:

php
Submit::make('Next')
    ->icon('ArrowRightIcon')
    ->iconPosition('right');

Loading State ​

While the form is submitting, the button that submitted it may show a different label and icon.

Loading Label ​

To change the button text while the form is submitting, use the loadingLabel method:

php
Submit::make('Save')->loadingLabel('Saving...');
Submit::make('Save Entry')->loadingLabel('Saving...');

Loading Icon ​

The loadingIcon method shows a different icon while the form is submitting:

php
Submit::make('Save')
    ->icon('SaveIcon')
    ->loadingIcon('LoaderCircleIcon');

Submit Behavior ​

These methods control what the button adds to the request and whether it may submit the form at all.

Multiple Submit Actions ​

A form may have more than one submit action, and your controller may need to know which button was clicked. To tell them apart, use the name and value methods. Give related actions the same name and distinct values:

php
Submit::make('Save Draft')
    ->name('intent')
    ->value('draft')
    ->secondary();

Submit::make('Publish')
    ->name('intent')
    ->value('publish')
    ->loadingLabel('Publishing...');

The rendered button uses native name and value attributes. On submit, the generated <Form> reads the clicked submitter and adds only that button's name and value pair to the request data. Disabled buttons and buttons without a name don't add submitter data. As with native HTML forms, the submitted value is read from the rendered button element. Your controller may then validate and read the value:

php
// In your controller, where $request is the incoming Illuminate\Http\Request...
$validated = $request->validate([
    'title' => ['required', 'string'],
    'intent' => ['nullable', 'in:draft,publish'],
]);

if ($validated['intent'] === 'publish') {
    // Publish the model...
}

Manual form wrappers should pass the submit event's submitter to form.submit(...) when the clicked button's data matters. See Submitter Data In Manual Forms.

Disabled ​

To prevent submission, you may disable the button:

php
Submit::make('Save')->disabled();

Combining Options ​

The methods above may be chained on one button:

php
Submit::make('Save Entry')
    ->primary()
    ->lg()
    ->fullWidth()
    ->icon('SaveIcon')
    ->loadingLabel('Saving...')
    ->loadingIcon('LoaderCircleIcon');

Shared Field APIs ​

The submit methods above compose with the shared field APIs:

Submit is excluded from the initial form data. Its name and value pair is submitted only for the activated button. Only class, controlClass, and wrapperClass render for Submit, since the button doesn't use FieldWrapper.

Using the Component Directly ​

SubmitButton is exported from the components subpath of each package. You may use it for standalone actions or while rendering forms manually. For icons, pass an icon resolver:

vue
<script setup lang="ts">
import type { IconResolverFn } from '@inertiaui/form-vue'
import { SubmitButton } from '@inertiaui/form-vue/components'
import { LoaderCircle, Save } from '@lucide/vue'

const icons = {
    SaveIcon: Save,
    LoaderCircleIcon: LoaderCircle,
}

const iconResolver: IconResolverFn = (icon) => icons[icon as keyof typeof icons] ?? null
const isReady = true
const trackSave = () => {}
</script>

<template>
    <SubmitButton
        id="save-entry"
        type="submit"
        name="intent"
        value="save"
        label="Save Entry"
        loading-label="Saving..."
        icon="SaveIcon"
        loading-icon="LoaderCircleIcon"
        :icon-resolver="iconResolver"
        variant="primary"
        size="lg"
        :full-width="true"
        icon-position="left"
        :disabled="!isReady"
        class="shadow-none"
        control-class="tracking-normal"
        wrapper-class="flex justify-end"
        data-testid="save-entry"
        @click="trackSave"
    />
</template>
tsx
import type { IconResolverFn } from '@inertiaui/form-react'
import { SubmitButton } from '@inertiaui/form-react/components'
import { LoaderCircle, Save } from 'lucide-react'

const icons = {
    SaveIcon: Save,
    LoaderCircleIcon: LoaderCircle,
}

const iconResolver: IconResolverFn = (icon) => icons[icon as keyof typeof icons] ?? null

export default function CreateButton() {
    const isReady = true
    const trackSave = () => {}

    return (
        <SubmitButton
            id="save-entry"
            type="submit"
            name="intent"
            value="save"
            label="Save Entry"
            loadingLabel="Saving..."
            icon="SaveIcon"
            loadingIcon="LoaderCircleIcon"
            iconResolver={iconResolver}
            variant="primary"
            size="lg"
            fullWidth
            iconPosition="left"
            disabled={!isReady}
            class="shadow-none"
            controlClass="tracking-normal"
            wrapperClass="flex justify-end"
            data-testid="save-entry"
            onClick={trackSave}
        />
    )
}

Native attributes and listeners target the underlying native element. See Native Attributes And Events.