# Conditional fields

Hide a field while another field has a certain value, so editors see only the fields that apply.

## The condition

Every field and setting takes `.hidden(condition)`, and `f.when(path)` builds the condition:

| Name | Description |
| --- | --- |
| `f.when(path).is(value)` | Hidden while the field at path equals value. |
| `f.when(path).isNot(value)` | Hidden while it differs. |
| `f.when(path).in([a, b])` | Hidden while it is one of the listed values. |
| `f.when(path).isEmpty()` | Hidden while it is empty: unset, an empty string or list, or an image with no asset. |
| `f.when(path).isNotEmpty()` | Hidden while it has a value. |

A hidden field leaves the form and is skipped at publish, so a required field that is hidden is not required. Its stored value stays, and comes back when the condition stops holding.

## Paths

A bare path names a sibling: a field at the same level as the one being hidden. Inside an object or a list item, that is the item's own fields. A path prefixed with `fields.` or `settings.` names a top-level key of that group from anywhere.

A link that is either a page on the site or an external address:

**Astro**

The schema goes in `src/components/sections/Banner.schema.ts`, written as in the Next.js tab. Its view, `src/sections/banner.astro`, picks the link the same way, through `safeHref` since an editor typed it: `href={safeHref(cta.kind === "external" ? cta.url : cta.path)}`.

**Next.js**

File: `components/sections/Banner.tsx`

```tsx
import { f, smoodly, type Props } from "smoodly/react";

export const bannerSchema = smoodly.schema.section({
  name: "banner",
  title: "Banner",
  fields: {
    heading: f.text(),
    cta: f.object({
      label: f.text(),
      kind: f.radio([{ value: "internal", label: "Page" }, { value: "external", label: "Address" }]).default("internal"),
      path: f.link().hidden(f.when("kind").is("external")),
      url: f.link().hidden(f.when("kind").is("internal")),
      newTab: f.boolean().hidden(f.when("kind").is("internal")),
    }),
  },
  settings: {
    tone: f.radio([{ value: "light", label: "Light" }, { value: "dark", label: "Dark" }]).default("light"),
    background: f.image().optional().hidden(f.when("settings.tone").is("light")),
  },
});

function BannerView({ heading, cta, settings, styles }: Props<typeof bannerSchema>) {
  const href = cta.kind === "external" ? cta.url : cta.path;
  return (
    <smoodly.Section styles={styles} className="banner" data-tone={settings.tone}>
      <h2>{heading}</h2>
      <a href={href} target={cta.newTab ? "_blank" : undefined} rel={cta.newTab ? "noopener" : undefined}>{cta.label}</a>
    </smoodly.Section>
  );
}

export const Banner = smoodly.section(bannerSchema, BannerView);
```

Inside `cta`, `kind` is a sibling of `path` and `url`, so the bare path reads it. The background setting reads `settings.tone` with the prefix. A condition that names a field the schema does not have fails at startup, not in the form.

The view still receives hidden fields as typed, so the sample above branches on `kind` itself rather than trusting that one of the two links is empty.

Next, the [Pages](https://smoodly.io/docs/pages/page-tree.md) group covers what editors do with pages once the shapes exist.
