Dyrecteddyrected
Recipes

Show an Admin Field Only When Relevant

Use a serializable condition without confusing presentation with security.

Conditional fields reduce clutter by reacting to sibling values in the editor.

Use a serializable Admin condition to reveal a field from the editor's current form values.

Use this when

  • show a field conditionally
  • hide irrelevant form fields
  • show discount only with a coupon
  • make the admin form react to another field

Dyrected concepts

admin.condition, Jexl, conditional fields

Additional packages: No additional packages.

Complete recipe

This is the canonical source compiled and behavior-tested by @dyrected/knowledge.

import { defineCollection, defineNumberField, defineTextField } from "@dyrected/core";

export const Orders = defineCollection({
  slug: "orders",
  fields: [
    defineTextField({ name: "couponCode", label: "Coupon code" }),
    defineNumberField({
      name: "discountPercent",
      label: "Discount percentage",
      admin: { condition: "couponCode != null && couponCode != ''" },
    }),
  ],
});

Decisions and cautions

admin.condition controls visibility only. It does not validate a submitted value, erase a previously stored value, or prevent API clients from writing the field. Add server validation or access rules when the condition represents a business or security requirement.

Use a Jexl string for Cloud-synchronized configuration. A function condition is suitable only when the configuration remains executable in the same trusted runtime.

Alternative

Use separate collections or blocks when the variants have substantially different lifecycle, access, or schema—not merely a few conditional inputs.

On this page