Link
The Link field captures a URL as either a plain string or a structured object with optional label and target values.
Plain URL Mode
Plain mode is the default, and the submitted value is a string:
use InertiaUI\Forms\Fields\Link;
Link::make('url');The field submits the URL itself:
"https://example.test"In plain mode, the PHP field reads the url key of a bound value that holds an array or an Arrayable object. Calling the plain method also turns off withLabel and withTarget.
Structured Mode
To save link metadata along with the URL, you may call the withLabel or withTarget method:
Link::make('cta')
->withLabel()
->withTarget();The field then submits an object:
{
"url": "https://example.test",
"label": "Read the guide",
"target": "_blank"
}The structured method opts into structured mode without the label or target controls:
Link::make('source')->structured();Structured values always contain a string url. The optional label and target keys are included only when their controls are enabled. A bound string is normalized to { "url": "..." }, and missing or null values become empty strings for the enabled keys.
URL Schemes
By default, users may enter a URL without a scheme, such as example.test/docs. A scheme that is present must be allowed. To require a scheme, call the requireScheme method:
Link::make('url')->requireScheme();The default allowed schemes are http and https. To restrict them, pass an array or variadic strings to the allowedSchemes method:
Link::make('url')->allowedSchemes(['https']);
Link::make('callback')->allowedSchemes('https', 'web+docs');The values are lowercased, surrounding : and / characters are removed, and duplicates are discarded. An empty or invalid scheme list is rejected. Without requireScheme, a value without a scheme is still accepted as long as http or https is allowed, but any scheme that is present must be allowed.
Validation
Plain mode adds the string rule plus the package URL rule. Structured mode adds an array rule and validates the nested url, label, and target paths:
Link::make('cta')
->withLabel()
->withTarget()
->requireScheme()
->required();This example validates cta.url as required, and checks that cta.target is empty or one of _self, _blank, _parent, or _top. Without a top-level required call, the nested URL is nullable. Enabled labels are nullable strings.
The Link methods above compose with the shared field APIs:
- Form Class for labels, help text, and placeholders.
- Model Binding for
default. - Validation for rules, required fields, and precognition.
- Styling for classes and presentation helpers.
- Conditional Visibility and Authorization.
Using the Component Directly
You may render Link outside the generated <Form> by passing it serialized form.getField(...) props or local state:
<script setup lang="ts">
import type { LinkValue } from '@inertiaui/form-vue'
import { Link } from '@inertiaui/form-vue/components'
import { ref } from 'vue'
const cta = ref<LinkValue>({
url: 'https://example.test/docs',
label: 'Read the guide',
target: '_blank',
})
const isArchived = false
const isLocked = false
const hideLabel = false
const trackBlur = () => {}
</script>
<template>
<Link
v-model="cta"
id="marketing-link"
name="cta"
label="Call to action"
help="Use an HTTPS URL for public campaign links."
placeholder="https://example.test/docs"
mode="structured"
:require-scheme="true"
:allowed-schemes="['https']"
:with-label="true"
:with-target="true"
required
precognitive
:disabled="isArchived"
:readonly="isLocked"
:label-sr-only="hideLabel"
badge="Public"
badge-class="bg-zinc-100 text-zinc-700"
label-trailing="Optional"
label-trailing-class="text-zinc-500"
tooltip="Shown wherever this campaign is linked."
help-position="below"
layout="split"
control-position="end"
label-class="font-medium"
help-class="text-zinc-500"
error-class="text-red-600"
wrapper-class="max-w-3xl"
control-class="bg-white"
class="font-medium"
invalid
error="Enter a secure HTTPS URL."
data-testid="marketing-link"
aria-label="Campaign URL"
@blur="trackBlur"
/>
</template>import { useState } from 'react'
import type { LinkValue } from '@inertiaui/form-react'
import { Link } from '@inertiaui/form-react/components'
export function CallToAction() {
const [cta, setCta] = useState<LinkValue>({
url: 'https://example.test/docs',
label: 'Read the guide',
target: '_blank',
})
const isArchived = false
const isLocked = false
const hideLabel = false
const trackBlur = () => {}
return (
<Link
value={cta}
onValueChange={setCta}
id="marketing-link"
name="cta"
label="Call to action"
help="Use an HTTPS URL for public campaign links."
placeholder="https://example.test/docs"
mode="structured"
requireScheme
allowedSchemes={['https']}
withLabel
withTarget
required
precognitive
disabled={isArchived}
readonly={isLocked}
labelSrOnly={hideLabel}
badge="Public"
badgeClass="bg-zinc-100 text-zinc-700"
labelTrailing="Optional"
labelTrailingClass="text-zinc-500"
tooltip="Shown wherever this campaign is linked."
helpPosition="below"
layout="split"
controlPosition="end"
labelClass="font-medium"
helpClass="text-zinc-500"
errorClass="text-red-600"
wrapperClass="max-w-3xl"
controlClass="bg-white"
class="font-medium"
invalid
error="Enter a secure HTTPS URL."
data-testid="marketing-link"
aria-label="Campaign URL"
onBlur={trackBlur}
/>
)
}Vue uses v-model, and React uses a controlled value plus onValueChange. Native attributes and listeners target the URL input. See Native Attributes And Events.