Skip to content
JS Filters

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

NameTypeDescription
dataObjectvalid (Boolean) and message (String), the result so far
valMixedthe value, already read through lzb.editor.control.getValue
controlObjectcontrol settings: type, name, required, label and the rest

Additional Filters

NameDescription
lzb.editor.control.CONTROL_TYPE.validatespecific 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
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.

Was this article helpful?

Copyright © 2026 Lazy Blocks.