Series 6: Extensions Chapter 8 of 10

Conditional required fields

Editing content
Applies to: Extension “Conditional required fields” As of Sulu 3.0

This only exists with the extension “Conditional required fields”. If it is missing from your administration, the extension is not installed.

In short

A required field that belongs to a different display no longer blocks saving. Visible required fields stay required: they turn red, and Sulu reports The form contains invalid values. The extension is installed by development.

Some fields of a block only appear for a certain choice. Sulu demands them anyway, even if nobody sees them, and then reports only “The form contains invalid values”. The extension Conditional required fields checks a required field only where it is visible and not grayed out.

For everyone who maintains content, that means: fewer errors that cannot be found. A developer has to install the extension. The example shows the block Prices & packages.

Helpful first: 3.1 Building pages with blocks

Step 1 of 4 A display without the field

The block Prices & packages has the setting Display. With Packages (cards) you only see the packages with name and price. The field Columns belongs to the comparison table and is hidden here.

Step 2 of 4 The same setting with a table

Choose Comparison table. Now Columns * appears, and the row has the field Row title *. The asterisk stands for a required field. Both fields exist only in this display.

Step 3 of 4 Saving with an empty required field

Leave both fields empty and save. Sulu reports The form contains invalid values. Columns and Row title turn red, and below them it says “This field must have a value”. It is only saved once both fields have content.

Switch back to Packages (cards) and the fields are hidden again. The extension then no longer checks them. Without it, Sulu would also check hidden required fields and block saving.

Good to know

According to the documentation, a failed save also opens the collapsed blocks that contain an invalid field. This applies if the JavaScript of the bundle is in the admin. You then do not have to open each block individually.

Step 4 of 4 Installing it in your project

The extension is called SuluBlockValidationBundle. On Packagist it is at version 1.2.0 (as of October 22, 2026). It needs Sulu 3 and PHP 8.2 and is tested with Sulu 3.0.10.

  1. Install the package with the command below. Without Symfony Flex, enter the bundle in config/bundles.php.
  2. Clear the cache with bin/adminconsole cache:clear and reload the admin. The conditional check runs without any further setting.
  3. For the automatic unfolding, enter the JavaScript in assets/admin/package.json and assets/admin/app.js and rebuild the admin.

The usual expressions for visibleCondition and disabledCondition are understood on the data of the form, for example __parent.select_view == 'table'. A condition that the bundle does not understand leaves the field a required field. Nothing becomes looser by accident. With bin/adminconsole sulu:block-validation:schema page default you check a form without a browser. The command needs opis/json-schema. The MCP bundle of Sulu checks required fields itself and does not use these rules.

The expressions, the limits and the installation of the JavaScript are in the README on GitHub and in the folder docs.

Installation
composer require manuxi/sulu-block-validation-bundle
assets/admin/package.json (section dependencies)
"sulu-block-validation-bundle": "file:../../vendor/manuxi/sulu-block-validation-bundle/src/Resources/js"
assets/admin/app.js
import 'sulu-block-validation-bundle';

More on this