Aphex
Schema Types

URL

URL input with built-in format validation.

The url type stores URL values. It includes automatic URL format validation and renders as a URL-specific input field.

Definition

import type { URLField } from '@aphexcms/cms-core';
{
  name: 'website',
  type: 'url',
  title: 'Website',
  placeholder: 'https://example.com'
}

Properties

PropertyTypeRequiredDescription
namestringYesField identifier.
type'url'YesMust be 'url'.
titlestringYesLabel shown in the admin UI.
descriptionstringNoHelp text shown below the label.
placeholderstringNoPlaceholder text. Defaults to 'https://example.com'.
initialValuestring | () => string | Promise<string>NoDefault value.
validation(Rule) => RuleNoValidation rules.

Examples

Basic URL field

{
  name: 'link',
  type: 'url',
  title: 'External Link',
  validation: (Rule) => Rule.required()
}

With URI validation options

{
  name: 'website',
  type: 'url',
  title: 'Website URL',
  validation: (Rule) => Rule.uri({
    scheme: [/^https$/],        // Only HTTPS
    allowRelative: false         // Must be absolute
  })
}

Allow relative URLs

{
  name: 'internalLink',
  type: 'url',
  title: 'Internal Link',
  placeholder: '/about',
  validation: (Rule) => Rule.uri({
    allowRelative: true
  })
}

Validation

The uri() rule accepts an options object:

OptionTypeDefaultDescription
schemeRegExp[][/^https?$/]Allowed URL schemes.
allowRelativebooleanfalseAllow relative URLs (e.g. /about).
relativeOnlybooleanfalseOnly allow relative URLs.

Available rules: required(), uri(options?), regex(pattern, name?), custom(fn), error(msg), warning(msg), info(msg)

Edit on GitHub

Last updated on