Studio

Number

Schema type reference for the Number type.

A number. See the NumberDefinition reference for the full type definition.

Loading...
A number field used for a popularity rating

Any number. For example: 900, 900.0, 9E+2, or 9.0E+2.

Properties

  • Requiredtype

    Value must be set to number.

  • 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

These options apply to number fields. See the NumberOptions reference for the full type definition.

  • A list of predefined values the editor can pick from. The array can hold plain numbers, as in [1, 2], or titled objects, as in [{title: 'One', value: 1}].

  • Controls how the items defined in the list option are presented. If set to 'radio' the list will render radio buttons. If set to 'dropdown' you'll get a dropdown menu instead. Default is dropdown.

  • Controls how radio buttons are lined up. Use direction: 'horizontal|vertical' to render radio buttons in a row or a column. Default is vertical. Will only take effect if the layout option is set to radio.

  • 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

Chain these methods on the rule passed to validation. See the NumberRule 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.

  • Minimum value (inclusive).

  • Maximum value (inclusive).

  • Value must be less than the given limit.

  • Value must be greater than the given limit.

  • Value must be an integer (no decimals).

  • Specifies the maximum number of decimal places allowed.

  • Requires the number to be positive (>= 0).

  • Requires the number to be negative (< 0).

  • Create a custom validation.

  • 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.

Input

Response

{
  "_type": "movie",
  "popularity": 12.5,
  ...
}

Gotcha

Was this page helpful?