Skip to content

Latest commit

 

History

History
42 lines (31 loc) · 731 Bytes

error.md

File metadata and controls

42 lines (31 loc) · 731 Bytes

Error Field Part

Represent a field validation error (if there are several errors, the first one is used). If field has no validation error, this field part will be hidden.

Usage Example

Form model:

final class ProfileForm extends FormModel
{
    public ?int $age = null;

    public function getRules(): array
    {
        return [
            'age' => [new Number(asInteger: true, min: 18)],
        ];
    }
}

Prepare and validate form model:

$profileForm = new ProfileForm();
$profileForm->age = 17;
(new Validator())->validate($profileForm);

Widget:

echo Error::widget()->formAttribute($profileForm, 'age');

Result will be:

<div>Value must be no less than 18.</div>