From 96a6a64d4c1524c7bca0f6e14503688f73db3bef Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Thu, 25 Apr 2024 15:13:21 +0200 Subject: [PATCH] Add general example for form builder usage See #421 --- docs/php/api/form_builder/overview.md | 48 +++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/docs/php/api/form_builder/overview.md b/docs/php/api/form_builder/overview.md index 7f21e1c5..5e452270 100644 --- a/docs/php/api/form_builder/overview.md +++ b/docs/php/api/form_builder/overview.md @@ -48,6 +48,54 @@ In addition to the existing methods inherited by `AbstractForm`, `AbstractFormBu - `$objectActionName` can be used to set an alternative action to be executed by the database object action that deviates from the default action determined by the value of `$formAction`. - `$objectActionClass` is the name of the database object action class that is used to create or update the database object. +Example: + +```php +form->appendChildren([ + TextFormField::create('name') + ->label('wcf.foo.name') + ->description('wcf.foo.name.description') + ->required() + ->maximumLength(255) + ->addValidator(new FormFieldValidator('notFoo', function (TextFormField $formField) { + if ($formField->getValue() === 'foo') { + $formField->addValidationError( + new FormFieldValidationError( + 'isFoo', + 'wcf.foo.name.error.isFoo' + ) + ); + } + })), + BooleanFormField::create('isCool') + ->label('wcf.foo.isCool') + ->value(true) + ]); + } +} +``` ## `DialogFormDocument` -- 2.20.1