---
title: "lzb.editor.control.validate"
description: "JS filter `lzb.editor.control.validate` of the Lazy Blocks WordPress plugin."
url: "https://www.lazyblocks.com/docs/js-filters/lzb-editor-control-validate/"
lastUpdated: 2026-09-09
source: "js-filters/lzb-editor-control-validate.mdx"
---
# lzb.editor.control.validate

Decides whether a required control counts as filled in, and what the error under it says. The built-in check is `val !== '' && typeof val !== 'undefined'`, which passes for an empty object, an empty array and the string `"0"`, so anything stricter than "not blank" belongs here.

The filter runs only for control types whose `required_settings` restriction is on and only for controls that have Required turned on in the block builder. Everything else skips it.

## Attributes

| Name      | Type       | Description                                                                                                  |
| --------- | ---------- | ------------------------------------------------------------------------------------------------------------ |
| `data`    | **Object** | `valid` (**Boolean**) and `message` (**String**), the result so far                                          |
| `val`     | **Mixed**  | the value, already read through [lzb.editor.control.getValue](https://www.lazyblocks.com/docs/js-filters/lzb-editor-control-getvalue/) |
| `control` | **Object** | control settings: `type`, `name`, `required`, `label` and the rest                                           |

## Additional Filters

| Name                                       | Description            |
| ------------------------------------------ | ---------------------- |
| `lzb.editor.control.CONTROL_TYPE.validate` | specific controls only |

The type-specific filter is applied inside the generic one's argument list, so it runs first and the generic filter receives its `{ valid, message }` as the incoming `data`.

## Usage

```js title="JS"
wp.hooks.addFilter(
  "lzb.editor.control.my_json.validate",
  "my.custom.namespace",
  function (data, val) {
    if (!val || !val.title) {
      return { valid: false, message: "Add a title before saving." };
    }

    return data;
  },
);
```

The result is destructured as `{ valid, message }`, so returning `null` or `undefined` throws a `TypeError` while the control is being rendered. A string or a boolean does not throw but leaves `valid` undefined, which reads as invalid and shows the default message, `This control is required.` A falsy `valid` puts `message` in a red notice under the control and calls `lockPostSaving`, so the post cannot be saved until the check passes.

## Documentation Index
> Fetch the complete documentation index at: https://www.lazyblocks.com/llms.txt
> Fetch every page in a single file at: https://www.lazyblocks.com/llms-full.txt
