# Field conditions

Source: https://docs.qiick.io/externa/field-conditions

**Field conditions** let a collection field change visibility, readonly, or required based on **other field values** on the same item. Form UX (client) and server enforcement for `required` / `readonly` stay in sync.

> **Sources of truth**
> PHP: `App\Services\Collections\FieldConditionEvaluator`. TS: `resources/js/lib/field-conditions.ts`. Settings UI: field settings → Conditions. Stored under `collections_fields.settings.conditions`.

## Shape

```json
{
  "logic": "and",
  "rules": [{ "field": "status", "operator": "equals", "value": "published" }],
  "hidden": false,
  "readonly": true,
  "required": true
}
```

| Key        | Meaning                                                                          |
| ---------- | -------------------------------------------------------------------------------- |
| `logic`    | `and` (default) — all rules must match; `or` — any rule matches                  |
| `rules`    | Flat list of `{ field, operator, value? }` (no nested groups)                    |
| `hidden`   | When matched: hide field. Explicit `false` = **show-when** (hide unless matched) |
| `readonly` | When matched: lock field (server strips writes)                                  |
| `required` | When matched: require a value (server validation)                                |

Existing AND / `equals` rules keep working unchanged.

## Operators

| Operator                    | Value                     | Match when…                                                                  |
| --------------------------- | ------------------------- | ---------------------------------------------------------------------------- |
| `equals`                    | any                       | Loose string equality (arrays: contains expected); booleans tolerate `0`/`1` |
| `not_equals`                | any                       | Negation of `equals`                                                         |
| `contains`                  | string / number           | String substring, or array membership                                        |
| `empty`                     | —                         | `null`, blank string, or `[]`                                                |
| `not_empty`                 | —                         | Negation of `empty`                                                          |
| `gt` / `gte` / `lt` / `lte` | number or ISO date prefix | Numeric compare, or lexicographic ISO `YYYY-MM-DD…`                          |
| `in`                        | comma list or array       | Actual (or any array element) is in the list                                 |
| `not_in`                    | comma list or array       | Negation of `in`                                                             |

## Examples

**Show notes only when kind is custom (show-when):**

```json
{
  "logic": "and",
  "rules": [{ "field": "kind", "operator": "equals", "value": "custom" }],
  "hidden": false
}
```

**Require price when status is draft or review (OR + in):**

```json
{
  "logic": "or",
  "rules": [
    { "field": "status", "operator": "equals", "value": "draft" },
    { "field": "status", "operator": "in", "value": "review, pending" }
  ],
  "required": true
}
```

**Lock title after publish date is set (gte):**

```json
{
  "logic": "and",
  "rules": [
    { "field": "published_at", "operator": "gte", "value": "2020-01-01" }
  ],
  "readonly": true
}
```

## Kitchen Sink sketch

On a demo collection with `kind` (select), `status` (select), `amount` (number), `notes` (string):

1. Hide `notes` unless `kind` equals `custom`.
2. Require `amount` when `status` is `in` `draft, review` **or** `amount` `gt` `0` is not enough alone — prefer one rule set per effect.
3. Readonly `status` when `published_at` is `not_empty`.

## Out of scope

No Flow builder, no HTTP / external conditions, no nested rule groups. Extend via [Extending](https://docs.qiick.io/externa/extending) if you need that.

> **Related**
> [Field types](https://docs.qiick.io/externa/field-types) · [Collections](https://docs.qiick.io/externa/collections) · [Collection items](https://docs.qiick.io/externa/collection-items)
