Studio

URL

Schema type reference for the URL type.

A string which represents a URL. See the UrlDefinition reference for the full type definition.

Properties

  • Requiredtype

    Value must be set to url.

  • Requiredname

    The field name. This becomes the key in the document.

  • Human-readable label for the field.

  • If set to true, this field is hidden in the studio. You can also supply a callback function to make it a conditional field.

  • If set to true, this field is not editable in the studio. You can also supply a callback function to make it a conditional field.

  • Short description for editors of how the field is to be used.

  • The initial value used when creating new values of this type. Can be a literal value, or a resolver function that returns a literal value or a promise that resolves to one.

  • Lets you provide custom components to override the studio defaults in various contexts. The available keys are diff, field, input, item, and preview.

  • Marks a field or document type as deprecated in the studio interface and displays a user-defined message set through the single required reason property.

    If you deploy a GraphQL API schema, this property is translated into the @deprecated directive.

  • Supply a custom icon for this field. See the icons documentation for more information.

  • Placeholder text shown in the input when it has no value.

Options

The url type has no options of its own. Only the shared options below apply. See the UrlOptions reference for the full type definition.

  • Configures how Sanity Create interfaces with this field. Set exclude: true to leave the field out of Sanity Create, or purpose to describe what the field holds so that content mapping can use it.

  • Configures how Canvas interfaces with this field. Takes the same exclude and purpose properties as sanityCreate.

Validation

Every url field is validated with uri() even when you set no validation of your own, allowing the http and https schemes only. Supplying your own uri() rule replaces that default. See the UrlRule reference for the full type definition.

  • Ensures that this field exists.

  • Discards the validation rules set before it in the chain and makes the field optional. Rules chained after it still apply.

  • Validates the value as a URI. Takes an options object:

    scheme: A string, RegExp, or array of either, listing the allowed schemes. Defaults to ['http', 'https'].

    allowRelative: Whether to allow relative URLs. Defaults to false.

    relativeOnly: Whether to allow only relative URLs. Defaults to false.

    allowCredentials: Whether to allow a username or password in the URL. Defaults to false, so https://user:pass@example.com fails validation.

  • Creates a custom validation rule.

  • Sets a custom error message for the preceding validation rule.

  • Sets a custom warning message for the preceding validation rule. Warnings do not prevent publishing.

  • Sets a custom info message for the preceding validation rule. Info messages are purely informational and do not prevent publishing.

  • Gets the value of a sibling field to use in validation. Useful for creating validation rules that depend on the value of another field.

The url type stores a string and renders a single-line text input. That input always carries inputMode="url". Its type attribute is url by default, so the browser applies its own URL validation. When a uri() rule sets allowRelative: true, the attribute is text instead, so that the browser does not reject relative paths.

Input

Response

{
  "_type": "movie",
  "imageUrl": "https://example.com/poster.jpg",
  ...
}

To allow schemes beyond http and https, or to accept relative paths, supply your own uri() rule:

Was this page helpful?